C++ 代码
#include <cstdio>
#include <cmath>
const int maxn = 110;
int a[maxn][maxn];
int main(){
int N;
while(scanf("%d",&N),N !=0){
for(int i =0 ;i <N;i++)
for(int j =0;j <N;j++){
a[i][j] = abs(i-j)+1; //找的规律
}
for(int i =0 ;i < N;i++){
for(int j =0;j<N;j++){
printf("%d ",a[i][j]);
}
printf("\n");
}
printf("\n");
}
return 0;
}