C++ 代码
#include <iostream>
using namespace std;
int main()
{
int n,m,i,j,a[110][110],x1,y1,x2,y2;
do
{
cin>>n;
if(n==0) break;
x1=0;x2=n-1;y1=0;y2=n-1;m=0;
do
{
m++;
for(i=x1;i<=x2;i++)
for(j=y1;j<=y2;j++)
a[i][j]=m;
x1++;y1++;x2--;y2--;
}while(x1<=x2);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++) cout<<a[i][j]<<' ';
cout<<endl;
}
cout<<endl;
}while(n!=0);
return 0;
}