为什么 运行不出来
#include
int chess[8][8];
int count = 0;
int judge(int r,int c)
{
int i;
int j;
for(i=0;i<8;i++)
{
if(chess[i][c])
return 0;
}
for(i=r,j=c;i>=0&&j>=0;i--,j--)
{
if(chess [i][j])
return 0;
}
for(i=r,j=c;i>=0&&j<8;i--,j++)
{
if(chess[i][j])
return 0;
}
return 1;
}
void eightQueen()
{
int stack[10];
int top = 0;
int i,k;
while(top>=0)
for(;stack[top]<8; stack[top]++)
{
k = stack[top];
if(judge(top,k))
{
chess[top][k] = 1;
break;
}
}
if (top == 7 && stack[top]<8)
{
count++;
stack[top]++;
}
else if(stack[top] < 8 && top <7)
{
top++;
}
else if (stack[top] == 8 && top <=7)
{
for (i=0;i<8;i++)
{
chess[top][i] = 0;
chess[top-1][i] = 0;
}
stack[top--] = 0;
stack[top]++;
}
}
void main()
{
int i ;
int j ;
for(i=0;i<8;i++)
{
for(j=0;j<8;j++)
{
chess[i][j] = 0;
}
}
eightQueen();
printf("八皇后的个数%d",count);
}