AcWing 754. 平方矩阵 II
原题链接
简单
作者:
citrus_7
,
2021-02-01 14:06:47
,
所有人可见
,
阅读 278
#include <iostream>
using namespace std;
int main()
{
int n, a[100][100];
while (cin >> n, n)
{
for (int i = 0; i < n; i ++ )
{
a[i][i] = 1;
for (int j = i + 1, k = 2; j < n; j ++ , k ++ )
{
a[i][j] = k;
a[j][i] = k;
}
}
for (int i = 0; i < n; i ++ )
{
for (int j = 0; j < n; j ++ )
cout << a[i][j] << ' ';
cout << endl;
}
cout << endl;
}
return 0;
}
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int n, a[100][100];
while (cin >> n, n)
{
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 ++ )
cout << a[i][j] << ' ';
cout << endl;
}
cout << endl;
}
return 0;
}