外层循环控制行,内层循环控制列

#include <iostream>
using namespace std;
int main()
{
for (int i = 0; i < 4; i++) {
for (int j = 0; j <= 2 - i; j++) {
cout << " ";
}
for (int j = 0; j <= 2 * i; j++) {
cout << "*";
}
cout << endl;
}
for (int i = 0; i < 3; i++) {
for (int j = 0; j <= i; j++) {
cout << " ";
}
for (int j = 0; j <= 4 - 2 * i; j++) {
cout << "*";
}
cout << endl;
}
system("pause");
}

C++利用循环打印菱形星号,字母,空心_ios

#include <iostream>
using namespace std;
int main()
{
for (int i = 0; i < 4; i++) {
for (int j = 0; j <= 2 - i; j++) {
cout << " ";
}
for (int j = 0; j <= 2 * i; j++) {
cout << char('A' + i);
}
cout << endl;
}
for (int i = 0; i < 3; i++) {
for (int j = 0; j <= i; j++) {
cout << " ";
}
for (int j = 0; j <= 4 - 2 * i; j++) {
cout << char('C' - i);
}
cout << endl;
}
system("pause");
}

C++利用循环打印菱形星号,字母,空心_#include_02

#include <iostream>
using namespace std;
int main()
{
for (int i = 0; i < 4; i++) {
for (int j = 0; j <= 2 - i; j++) {
cout << " ";
}
for (int j = 0; j <= 2 * i; j++) {
if (j == 0 || j == 2 * i) {
cout << "*";
}
else {
cout << " ";
}
}
cout << endl;
}
for (int i = 0; i < 3; i++) {
for (int j = 0; j <= i; j++) {
cout << " ";
}
for (int j = 0; j <= 4 - 2 * i; j++) {
if (j == 0 || j == 4 - 2 * i) {
cout << "*";
}
else {
cout << " ";
}
}
cout << endl;
}
system("pause");
}

C++利用循环打印菱形星号,字母,空心_ios_03