#include
int main()
{
int a[3][3] = {0};
int i, j, n=3;
int col = 1, line = 0;
a[line][col] = 1;
for(i=2; i<10; i++)
{
line--;
col++;
if(line<0 && col<3)
line = n-1;
if(col>2 && line>=0)
col = 0;
if(line<0 && col>2)
{
line = line+2;
col = col-1;
}
if(a[line][col]!=0)
{
line = line+2;
col = col-1;
}
a[line][col] = i;
}
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
printf("%d ", a[i][j]);
printf("\n");
}
return 0;
}
我有解九宫的,要么