编写一个 C++ 程序,使用 for 循环打印空心镜像菱形星形图案。
#include<iostream>
using namespace std;
int main()
{
int i, j, k, rows;
cout << "Enter Hollow Mirrored Rhombus Star Pattern Row = ";
cin >> rows;
cout << "Hollow Mirrored Rhombus Star Pattern\n";
for(i = 1; i <= rows; i++)
{
for(j = 1; j < i; j++)
{
cout << " ";
}
for(k = 1; k <= rows; k++)
{
if (i == 1 || i == rows || k == 1 || k == rows)
{
cout << "* ";
}
else
{
cout << " ";
}
}
cout << "\n";
}
return 0;
}

这个 C++ 示例使用 while 循环打印给定字符的空心镜像菱形图案。
#include<iostream>
using namespace std;
int main()
{
int i = 1, j, k, rows;
char ch;
cout << "Enter Hollow Mirrored Rhombus Star Pattern Row = ";
cin >> rows;
cout << "Enter Symbol for Hollow Mirrored Rhombus Pattern = ";
cin >> ch;
cout << "Hollow Mirrored Rhombus Star Pattern\n";
while(i <= rows)
{
j = 1;
while(j < i)
{
cout << " ";
j++;
}
k = 1;
while(k <= rows)
{
if (i == 1 || i == rows || k == 1 || k == rows)
{
cout << ch << " ";
}
else
{
cout << " ";
}
k++;
}
cout << "\n";
i++;
}
return 0;
}
Enter Hollow Mirrored Rhombus Star Pattern Row = 14
Enter Symbol for Hollow Mirrored Rhombus Pattern = %
Hollow Mirrored Rhombus Star Pattern
% % % % % % % % % % % % % %
% %
% %
% %
% %
% %
% %
% %
% %
% %
% %
% %
% %
% % % % % % % % % % % % % %