编写一个 C++ 程序,使用 for 循环打印左递减数字图案的平方。
#include<iostream>
using namespace std;
int main()
{
int rows;
cout << "Enter Square of Left Dec Numbers Rows = ";
cin >> rows;
cout << "Square of Decrement Numbers from Left Side\n";
for (int i = rows; i >= 1; i--)
{
for (int j = i; j < rows; j++)
{
cout << j << " ";
}
for (int k = rows - i; k < rows; k++)
{
cout << rows << " ";
}
cout << "\n";
}
}

这个 C++ 程序 使用 while 循环显示左侧递减数字的平方图案。
#include<iostream>
using namespace std;
int main()
{
int rows, i, j, k;
cout << "Enter Square of Left Dec Numbers Rows = ";
cin >> rows;
cout << "Square of Decrement Numbers from Left Side\n";
i = rows;
while (i >= 1)
{
j = i;
while (j < rows)
{
cout << j << " ";
j++;
}
k = rows - i;
while (k < rows)
{
cout << rows << " ";
k++;
}
cout << "\n";
i--;
}
}
Enter Square of Left Dec Numbers Rows = 9
Square of Decrement Numbers from Left Side
9 9 9 9 9 9 9 9 9
8 9 9 9 9 9 9 9 9
7 8 9 9 9 9 9 9 9
6 7 8 9 9 9 9 9 9
5 6 7 8 9 9 9 9 9
4 5 6 7 8 9 9 9 9
3 4 5 6 7 8 9 9 9
2 3 4 5 6 7 8 9 9
1 2 3 4 5 6 7 8 9