# VBForums CodeBank > CodeBank - C++ >  C - 8 Queens Problem

## pradeepkrao

Hi,

I saw a very cryptic code for 8 queens problem in the internet.

Place 8 queens in a chess board such that no other queen is in the same row, column and diagnol.



```
# include<stdio.h>
int v,i,j,k,l,s,a[99];
main()
{
for(s=8;*a-s;v=a[j*=v]-a[i],k=i<s,j+=(v=j<s&&(!k&&!!printf(2+"\n\n%c"-(!l<<!j)," #Q"[l^v?(l^j)&1:2])&&++l||a[i]<s&&v&&v-i+j&&v+i-j))&&!(l%=s),v||(i==j?a[i+=k]=0:++a[i])>=s*k&&++a[--i]);
printf("\n\n");
}
```

My Code


```
# include<stdio.h>
# define Q  8
struct POINT {int x,y;}; 
POINT q[Q];
int N;
bool chkAll(int x){
	for ( int i =x ; i >=0 ; i--)
	for(int j = i - 1; j >= 0 ; j--)
	if(q[i].x == q[j].x || q[i].y == q[j].y || 
	   q[i].x + q[i].y == q[j].x + q[j].y || 
	   q[i].x - q[j].x == q[i].y - q[j].y)
	return false; return true;
}
void MoveQueen(int x){
	
	if(x >= Q)
	{	
		printf("\n\nSolution : %d \n\n\t",++N);
		for(int j=0;j<Q;printf("\n\t"),j++)
		for(int i=0;i<Q;((q[j].x==j) && (q[j].y==i))?printf("Q%c",179) : printf("_%c",179),i++);
		return;
	}	
	
	for (int j = 0; j < Q ;q[x].x = x,j++){	q[x].y = j;
		  if(chkAll(x)) MoveQueen(x + 1);
	}
}
void main(){for (int i = 0; i < Q; q[0].x = 0,q[0].y = i,MoveQueen(1),i++);}
```

Regards,
Pradeep

----------


## CornedBee

Could you deobfuscate that stuff?

----------


## pradeepkrao

Hi,

The code which I found in the internet.. ??????... I have no clue what it does but when compiled runs like a charm...

The problem is place 8 queens on a chess board in such a way that no other queen falls in the same diagnoal and verticle and horizontal.

Check my games section in my website, I have made that game in VB, there is a cheat code also which will give you the list of solutuions...

Regards,
Pradeep

----------


## tonyrueb

The program works great!! Just one thing, can you put comments on your code. i am trying to learn how to program and it would really help me out.

----------

