#include 

void find(int i);

class eightqueen {
	int a[8];
	int b[15];
	int c[15];
	int x[15];
public:
	void init(void);
	void set(int i, int j);
	void reset(int i, int j);
	int check(int i, int j);
	void locate(int i, int j);
	void print(void);
};
eightqueen eq;
void eightqueen::init(void)
{
	int i;
	for(i=0;i<8;i++) eq.a[i] = 1;
	for(i=0;i<15;i++) eq.b[i] = eq.c[i] = 1;
}
void eightqueen::set(int i, int j)
{
	eq.a[j] = eq.b[i+j] = eq.c[i-j+7] = 1;
}
void eightqueen::reset(int i, int j)
{
	eq.a[j] = eq.b[i+j] = eq.c[i-j+7] = 0;
}
int  eightqueen::check(int i, int j)
{
	if(eq.a[j] && eq.b[i+j] && eq.c[i-j+7]) return 1;
	else return 0;
}
void eightqueen::locate(int i, int j)
{
	eq.x[i] = j;
}
void eightqueen::print(void)
{
	int i;
	for(i=0;i<8;i++) cout << x[i] << '\t';
	cout << endl;
}
int g=0;
void main(void)
{
  	eq.init();
	find(0);
}
void find(int i)
{
	int j;
	for(j=0;j<8;j++) {
		if(eq.check(i,j)) {
			eq.locate(i,j);
			eq.reset(i,j);
			if(i<7) find(i+1);
			else eq.print();
			eq.set(i,j);
		}
	}
}

    Source: geocities.com/hsvfapa