写了个魔方阵的程序但不知道哪错了,编译没错,运行结果错了,求帮助
#include<stdio.h>int main()
{int x,y,k,n,z;
scanf("%d",&n);
int a[n][n];
for(x=0;x<=n-1;x++)
for(y=0;y<=n-1;y++)
a[x][y]=0;
x=0;y=n/2;
a[x][y]=1;
for(k=2;k<=n*n;k++)
{if((x-1<0)&&(y+1>n-1)||a[x-1][y+1]!=0){a[x+1][y]=k;x=x+1;y=y;continue;}
if((x-1<0)&&(y+1<=n-1)){a[n-1][y+1]=k;x=n-1;y=y+1;continue;}
if((x-1>=0)&&(y+1>n-1)){a[x-1][0]=k;x=x-1;y=0;continue;}
if((x-1>=0)&&(y+1<=n-1)){a[x-1][y+1]=k;x=x-1;y=y+1;continue;}
}
for(x=0;x<=n-1;x++)
for(y=0,z=1;y<=n-1;y++,z++)
{printf("%5d",a[x][y]);
if(z==n)printf("\n");}
return 0;
}