编写一个C++程序,使用for循环来打印降序数的倒右三角形图案。
#include using namespace std;
int main() { int i, j, rows;
cout << "Enter Inverted Right Triangle of Desc Numbers Rows = ";
cin >> rows;
cout << "Inverted Right Triangle of Numbers in Descending Ord Pattern\\n";
for(i = rows; i >= 1; i--)
{
for(j = i; j >= 1; j--)
{
cout << j << " ";
}
cout << "\\n";
}
return 0;
这个C++例子使用while循环打印降序数字的倒右三角形。
#include using namespace std;
int main() { int i, j, rows;
cout << "Enter Inverted Right Triangle of Desc Numbers Rows = ";
cin >> rows;
cout << "Inverted Right Triangle of Numbers in Descending Ord Pattern\\n";
i = rows;
while( i >= 1)
{
j = i;
while (j >= 1)
{
cout << j << " ";
j--;
}
cout << "\\n";
i--;
}
return 0;
Enter Inverted Right Triangle of Desc Numbers Rows = 15
Inverted Right Triangle of Numbers in Descending Ord Pattern
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
14 13 12 11 10 9 8 7 6 5 4 3 2 1
13 12 11 10 9 8 7 6 5 4 3 2 1
12 11 10 9 8 7 6 5 4 3 2 1
11 10 9 8 7 6 5 4 3 2 1
10 9 8 7 6 5 4 3 2 1
9 8 7 6 5 4 3 2 1
8 7 6 5 4 3 2 1
7 6 5 4 3 2 1
6 5 4 3 2 1
5 4 3 2 1
4 3 2 1
3 2 1
2 1
1