观察矩阵的生成方法写就完事啦
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 105;
int num[N][N];
int main() {
int n;
cin >> n;
while (n) {
for (int i = 1;i <= n;i++) num[i][i] = 1;
for (int i = 1;i <= n;i++) {
int k = 0;
for (int j = i;j > 0;j--) {
num[i][j] = k + 1;
k++;
}
k = 0;
for (int j = i;j <= n;j++) {
num[i][j] = k + 1;
k++;
}
}
for (int i = 1;i <= n;i++) {
for (int j = 1;j <= n;j++) {
cout << num[i][j] << ' ';
}
cout << endl;
}
cout << endl;
cin >> n;
}
return 0;
}