# include<stdio.h>
int main()
{
int n,count=1,t,flag=0;
scanf("%d",&n);
int a[n+1][n+1];
int i=0,j=n+1;
int hb=1,zb=n;
int k = (n+1)/2;
while(i!=k&&j!=k)
{
if(flag==0)//有四个状态列不变行递增 行不变列递减 列不变行递减 行不变列递增 故用4个if 再用hb zb控制边界情况
{
i=i+1;j=j-1;
flag=1;
for(i;i<=zb;i++)
{
a[i][j]=count;count++;
//printf("%d %d %d %d
",i,j,count,a[i][j]);
}
}
else if(flag==1)
{
flag=2;
j=j-1;i=i-1;
for(j;j>=hb;j--)
{
a[i][j]=count;count++;
// printf("%d %d %d %d
",i,j,count,a[i][j]);
}
}
else if(flag==2)
{
flag=3;
i=i-1;j=j+1;
for(i;i>=hb;i--)
{
a[i][j]=count;count++;
// printf("%d %d %d %d
",i,j,count,a[i][j]);
}
hb=hb+1;
}
else
{
flag=0;
j=j+1;i=i+1;
zb=zb-1;
for(j;j<=zb;j++)////牢记j退出来时会比边界条件大
{
a[i][j]=count;count++;
// printf("%d %d %d %d
",i,j,count,a[i][j]);
}
}
}
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
printf("%d ",a[i][j]);
}
printf("
");
}
return 0;
}