//输出螺旋方阵
#include <iostream>
using namespace std;
void main()
{
int i,j,n,k;
int a[100][100];
cout <<"请输入方阵的阶数:"<<endl;
cin >>n;
a[0][0]=1;
for(k=n;k<(n+1)/2;k--,a[n-k][n-k]=a[n-k][n-k+1]+1)
{
i=n-k;
for(j=n-k+1;j<k;j++)
{
a[i][j]=a[n-k][n-k]+j;
}
j=k-1;
for(i=n-k+1;i<k;i++)
{
a[i][j]=a[n-k][k-1]+i;
}
i=k-1;
for(j=k-1-1;j>=n-k;j--)
{
a[i][j]=a[k-1][k-1]+(k-1)-j;
}
j=n-k;
for(i=k-1-1;i>n-k;i--)
{
a[i][j]=a[k-1][n-k]+(k-1)-i;
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
cout <<a[i][j];
cout <<"\t";
}
cout <<endl;
}
}