C++输出以下图案 * *** ***** ******* ***** *** *
时间: 2023-11-26 11:05:59 浏览: 79
以下是C++输出该图案的代码:
```cpp
#include <iostream>
using namespace std;
int main() {
int n;
char c;
cout << "How many lines? ";
cin >> n;
cout << "What character? ";
cin >> c;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= 2 * n - 1; j++) {
if (j <= n - i || j >= n + i) {
cout << " ";
} else {
cout << c;
}
}
cout << endl;
}
for (int i = n - 1; i >= 1; i--) {
for (int j = 1; j <= 2 * n - 1; j++) {
if (j <= n - i || j >= n + i) {
cout << " ";
} else {
cout << c;
}
}
cout << endl;
}
return 0;
}
```
阅读全文