编写一个 C++ 程序,使用 for 循环打印倒三角形镜像字母图案。
#include<iostream>
using namespace std;
int main()
{
int rows;
cout << "Enter Downward Triangle of Mirrored Alphabets Rows = ";
cin >> rows;
cout << "The Downward Triangle of Mirrored Alphabets Pattern\n";
int alphabet = 65;
for (int i = 0; i <= rows - 1; i++)
{
for (int j = i; j <= rows - 1; j++)
{
cout << char(alphabet + j) << " ";
}
for (int k = rows - 2; k >= i; k--)
{
cout << char(alphabet + k) << " ";
}
cout << "\n";
}
}

这个 C++ 示例 使用 while 循环打印倒三角形镜像字母图案。
#include<iostream>
using namespace std;
int main()
{
int rows, i, j, k, alphabet;
cout << "Enter Downward Triangle of Mirrored Alphabets Rows = ";
cin >> rows;
cout << "The Downward Triangle of Mirrored Alphabets Pattern\n";
alphabet = 65;
i = 0;
while (i <= rows - 1)
{
j = i;
while (j <= rows - 1)
{
cout << char(alphabet + j);
j++;
}
k = rows - 2;
while (k >= i)
{
cout << char(alphabet + k);
k--;
}
cout << "\n";
i++;
}
}
Enter Downward Triangle of Mirrored Alphabets Rows = 17
The Downward Triangle of Mirrored Alphabets Pattern
ABCDEFGHIJKLMNOPQPONMLKJIHGFEDCBA
BCDEFGHIJKLMNOPQPONMLKJIHGFEDCB
CDEFGHIJKLMNOPQPONMLKJIHGFEDC
DEFGHIJKLMNOPQPONMLKJIHGFED
EFGHIJKLMNOPQPONMLKJIHGFE
FGHIJKLMNOPQPONMLKJIHGF
GHIJKLMNOPQPONMLKJIHG
HIJKLMNOPQPONMLKJIH
IJKLMNOPQPONMLKJI
JKLMNOPQPONMLKJ
KLMNOPQPONMLK
LMNOPQPONML
MNOPQPONM
NOPQPON
OPQPO
PQP
Q