C++题解
2024-05-19 21:04:04
发布于:四川
10阅读
0回复
0点赞
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
int a;
cin>>a;
for (int i = 1; i <= a; ++i) {
for (int j = a - i; j >= 1; --j) {
cout << " ";
}
for (int j = i * 2 - 1; j >= 1; --j) {
if (j == i * 2 - 1 || j == 1) {
cout << "*";
} else {
cout << " ";
}
}
cout << endl;
}
for (int i = a - 1; i >= 1; --i) {
for (int j = a - i; j >= 1; --j) {
cout << " ";
}
for (int j = i * 2 - 1; j >= 1; --j) {
if (j == i * 2 - 1 || j == 1) {
cout<<"*";
} else {
cout<<" ";
}
}
cout << endl;
}
return 0;
}
这里空空如也
有帮助,赞一个