题目描述
输入整数N,输出相应方阵。
输入
一个整数N。( 0 < n < 10 )
输出
一个方阵,每个数字的场宽为3。
样例输入
复制
5
样例输出
复制
1 2 3 4 5
2 3 4 5 4
3 4 5 4 3
4 5 4 3 2
5 4 3 2 1
点个赞吧,还有关注!!!
上代码!!!
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, x, s;
cin >> n;
for (int i = 1; i <= n; i++)
{
x = i;
s = 0;
for (int j = 1; j <= n; j++)
{
cout << " " << x;
if (x == 1)
{
s = 0;
}
if (x == n)
{
s = 1;
}
if (s == 0)
{
x++;
}
else
{
x--;
}
}
cout << endl;
}
return 0;
}
439





