编写一个C++程序,使用for循环打印左箭头数字图案。
#include<iostream>
using namespace std;
int main()
{
int rows, i, j;
cout << "Enter Left Arrow Number Pattern Rows = ";
cin >> rows;
cout << "The Left Arrow Numbers Pattern\n";
for (i = rows; i >= 1; i--)
{
for (j = i; j >= 1; j--)
{
cout << j << " ";
}
cout << "\n";
}
for (i = 2; i <= rows; i++)
{
for (j = i; j >= 1; j--)
{
cout << j << " ";
}
cout << "\n";
}
}

C++程序使用while循环打印左箭头数字图案。
#include<iostream>
using namespace std;
int main()
{
int rows, i, j;
cout << "Enter Left Arrow Number Pattern Rows = ";
cin >> rows;
cout << "The Left Arrow Numbers Pattern\n";
i = rows;
while (i >= 1)
{
j = i;
while (j >= 1)
{
cout << j << " ";
j--;
}
cout << "\n";
i--;
}
i = 2;
while (i <= rows)
{
j = i;
while (j >= 1)
{
cout << j << " ";
j--;
}
cout << "\n";
i++;
}
}
Enter Left Arrow Number Pattern Rows = 12
The Left Arrow Numbers Pattern
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
2 1
3 2 1
4 3 2 1
5 4 3 2 1
6 5 4 3 2 1
7 6 5 4 3 2 1
8 7 6 5 4 3 2 1
9 8 7 6 5 4 3 2 1
10 9 8 7 6 5 4 3 2 1
11 10 9 8 7 6 5 4 3 2 1
12 11 10 9 8 7 6 5 4 3 2 1
本示例使用do while循环显示数字左箭头图案。
#include<iostream>
using namespace std;
int main()
{
int rows, i, j;
cout << "Enter Left Arrow Number Pattern Rows = ";
cin >> rows;
cout << "The Left Arrow Numbers Pattern\n";
i = rows;
do
{
j = i;
do
{
cout << j << " ";
} while (--j >= 1);
cout << "\n";
} while (--i >= 1);
i = 2;
do
{
j = i;
do
{
cout << j << " ";
} while (--j >= 1);
cout << "\n";
} while (++i <= rows);
}
Enter Left Arrow Number Pattern Rows = 16
The Left Arrow Numbers Pattern
16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
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
2 1
3 2 1
4 3 2 1
5 4 3 2 1
6 5 4 3 2 1
7 6 5 4 3 2 1
8 7 6 5 4 3 2 1
9 8 7 6 5 4 3 2 1
10 9 8 7 6 5 4 3 2 1
11 10 9 8 7 6 5 4 3 2 1
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
14 13 12 11 10 9 8 7 6 5 4 3 2 1
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1