C++ 代码
#include <iostream>
using namespace std;
int main(){
int n;
while(scanf("%d",&n)){
if(n==0)
break;
int a[n+2][n+2];
for(int i=1;i<=n;i++){
for(int j=0;j<=n-i;j++){
a[1+j][i+j]=i;
a[i+j][1+j]=i;
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++)
cout << a[i][j] << " ";
cout << "\n";
}
cout << "\n";
}
return 0;
}