#include<stdio.h>
#define N 20
int main(int argc, int *argv[])
{
int a[N][N];
int n,i,j,r;
scanf("%d",&n);
for(i=0;i<N;i++)
{
for(j=0;j<N;j++)
{
a[i][j]=0;
}
}
i=0;
j=n/2;
a[i][j]=1;
for (r=2;r<=n*n;r++)
{
if (a[(i+n-1)%n][(j+1)%n]==0)
{
i=(i+n-1)%n;j=(j+1)%n;
a[i][j]=r;
}
else
{
i=(i+1)%n;
a[i][j]=r;
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf("%4d",a[i][j]);
}
printf("\n");
}
system("pause");
return 0;
}
|