编译没问题,组建有问题,错在哪里?
下列程序编译没问题,但是组建有问题,请问错在哪里?#include <stdio.h>
int mian(void)
{
int a[15][15],i,j,k,p,n;
p = 1;
while(p == 1)
{
printf("请输入魔方阵的阶数(该魔方阵的阶数为1到15):\n");
scanf("%d",&n);
if((n!=0) && (n%2 != 0) && (n<=15))
p= 0;
}
for (i = 1;i<=n;i++)
{
for(j = 1;j<=n;j++)
a[i][j] = 0;
}
j = n/2 + 1;
a[1][j] = 1;
for(k = 2;k<=n*n;k++)
{
i = i -1;
j = j + 1;
if((i<1) && (j > n) )
{
i = i + 2;
j = j - 1;
}
else
{
if(i<1)
i = n;
if(j>n)
j = 1;
}
if(a[i][j] == 0)
a[i][j] = k;
else
{
i = i + 2;
j = j - 1;
a[i][j] = k;
}
}
for(i = 1;i<=n;i++)
{
for(j = 1;j<=n;j++)
printf("%5d",a[i][j]);
printf("\n");
}
return 0;
}