1 #include <stdio.h>
2 #include<string.h>
3 #define maxn 102
4 int a[maxn][maxn];
5 int main()
6 {
7 int n,x,y,tot=0;
8 scanf("%d",&n);
9 memset(a,0,sizeof(a));
10 tot=a[x=0][y=n-1]=1;
11 while(tot<n*n) //计算二维数组存储值
12 {
13 while(x+1<n&&!a[x+1][y])a[++x][y]=++tot;
14 while(y-1>=0&&!a[x][y-1])a[x][--y]=++tot;
15 while(x-1>=0&&!a[x-1][y])a[--x][y]=++tot;
16 while(y+1<n &&!a[x][y+1])a[x][++y]=++tot;
17 }
18 for(x=0;x<n;x++)
19 {
20 for(y=0;y<n;y++)
21 {
22 printf("%d",a[x][y]);
23 }
24 printf("
");
25 }
26 return 0;
27 }