使用 for 循环编写一个 C++ 程序来打印右箭头数字图案。
#include<iostream>
using namespace std;
int main()
{
int i, j, rows;
cout << "Enter Right Arrow Number Pattern Row = ";
cin >> rows;
cout << "Right Arrow Number Pattern\n";
for(i = 1; i <= rows; i++)
{
for(j = 1; j <= rows; j++)
{
if(j < i) {
cout << " ";
}
else {
cout << j;
}
}
cout << "\n";
}
for(i = 1; i < rows; i++)
{
for(j = 1; j <= rows; j++)
{
if(j < rows - i) {
cout << " ";
}
else {
cout << j;
}
}
cout << "\n";
}
return 0;
}

这个 C++ 示例 使用 while 循环以右箭头图案打印数字。
#include<iostream>
using namespace std;
int main()
{
int i = 1, j, rows;
cout << "Enter Right Arrow Number Pattern Row = ";
cin >> rows;
cout << "Right Arrow Number Pattern\n";
while(i <= rows)
{
j = 1;
while( j <= rows)
{
if(j < i) {
cout << " ";
}
else {
cout << j;
}
j++;
}
cout << "\n";
i++;
}
i = 1;
while( i < rows)
{
j = 1;
while( j <= rows)
{
if(j < rows - i) {
cout << " ";
}
else {
cout << j;
}
j++;
}
cout << "\n";
i++;
}
return 0;
}
Enter Right Arrow Number Pattern Row = 9
Right Arrow Number Pattern
123456789
23456789
3456789
456789
56789
6789
789
89
9
89
789
6789
56789
456789
3456789
23456789
123456789