0
点赞
收藏
分享

微信扫一扫

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

鱼板番茄 2022-05-23 阅读 66


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

#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++利用循环打印菱形星号,字母,空心_#include

#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++利用循环打印菱形星号,字母,空心_i++_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++利用循环打印菱形星号,字母,空心_i++_03



举报

相关推荐

0 条评论