I have been trying to debug this code I made, it outputs only 1's in the first row of the array and all other elements are zero(from second row till the last element.), is it the problem of function calling of passing the array by value or something else. Help appreciated.
#include<stdio.h>
#include<stdlib.h>
int isSafe(int x, int y, int a[][8])
{ int i,j;
//for left check of the cols
for(i=0;i<y;i++)
{
if(a[x][i]==1)
return 0;
}
//for check of left upper diagonals
for (i = x, j = y; i >= 0 && j >= 0; i--, j--)
{
if(a[i][j]==1)
return 0;
}
//for check of left lower diagonals
for(i = x, j = y; i<=7 && j>=0; i++,j--)
{
if(a[i][j]==1)
return 0;
}
return 1;
}//close isSafe
int EQueen(int a[][8], int q)
{
int c=0;
if(q==8)
return 1;
else
{
while(c<=7)
{
if(isSafe(q,c,a)==1)
{
a[c][q] = 1;
if(EQueen(a,q+1)==1)
return 1;
else
a[c][q] = 0;
}//close if
c++;
}//close while
return 0;
}//close else
}//close EQueen
int main()
{
int i,j,chess[8][8] = {[0 ... 7][0 ... 7] = 0};
if(EQueen(chess,0)==1)
{
for(i=0;i<8;i++)
{
for(j=0;j<8;j++)
printf("%d ",chess[i][j]);
printf("\n");
}
}
return 0;
}//close main