编写一个 C++ 程序,使用 for 循环打印空心倒直角三角形星形图案。
#include<iostream>
using namespace std;
int main()
{
int i, j, rows;
cout << "Enter Hollow Inverted Right Triangle Star pattern Rows = ";
cin >> rows;
cout << "Hollow Inverted Right Angled Triangle Star Pattern\n";
for(i = rows; i > 0; i--)
{
for(j = 1; j <= i; j++)
{
if(j == 1 || j == i || i == 1 || i == rows)
{
cout << "*";
}
else
{
cout << " ";
}
}
cout << "\n";
}
return 0;
}

此 C++ 图案示例 使用 while 循环打印给定字符的空心倒直角三角形。
#include<iostream>
using namespace std;
int main()
{
int i, j, rows;
char ch;
cout << "Enter Rows = ";
cin >> rows;
cout << "Enter Symbol = ";
cin >> ch;
i = rows;
while( i > 0)
{
j = 1;
while( j <= i)
{
if(j == 1 || j == i || i == 1 || i == rows)
{
cout << ch;
}
else
{
cout << " ";
}
j++;
}
cout << "\n";
i--;
}
return 0;
}
Enter Rows = 15
Enter Symbol = $
$$$$$$$$$$$$$$$
$ $
$ $
$ $
$ $
$ $
$ $
$ $
$ $
$ $
$ $
$ $
$ $
$$
$