编写一个C++程序,使用for循环打印镜像菱形星形图案。
#include using namespace std;
int main() { int i, j, k, rows;
cout << "Enter Mirrored Rhombus Star Pattern Row = ";
cin >> rows;
cout << "Mirrored Rhombus Star Pattern\\n";
for(i = 1; i <= rows; i++)
{
for(j = 1; j <= i; j++)
{
cout << " ";
}
for(k = 1; k <= rows; k++)
{
cout << "\*";
}
cout << "\\n";
}
return 0;
这个C++例子使用while循环打印一个给定字符的镜像菱形图案。
#include using namespace std;
int main() { int i = 1, j, k, rows; char ch;
cout << "Enter Mirrored Rhombus Star Pattern Row = ";
cin >> rows;
cout << "Enter Symbol for Mirrored Rhombus Pattern = ";
cin >> ch;
cout << "Mirrored Rhombus Star Pattern\\n";
while(i <= rows)
{
j = 1;
while(j <= i)
{
cout << " ";
j++;
}
k = 1;
while( k <= rows)
{
cout << ch;
k++;
}
cout << "\\n";
i++;
}
return 0;
Enter Mirrored Rhombus Star Pattern Row = 16
Enter Symbol for Mirrored Rhombus Pattern = %
Mirrored Rhombus Star Pattern
%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%