用c++输出以下图案: * * * * * * * * * * * * * * * * * * * * * * * * *
时间: 2023-11-09 19:03:22 浏览: 100
以下是用C++输出图案的代码:
```
#include <iostream>
using namespace std;
int main() {
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= i; j++) {
cout << "* ";
}
cout << endl;
}
cout << " * " << endl;
return 0;
}
```
输出结果为:
```
*
* *
* * *
* * * *
* * * * *
*
```
相关问题
C++输出以下图案 * *** ***** ******* ***** *** *
以下是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;
}
```
C++输出以下图案:+*+***+*****+*******+输入n
以下是C++输出图案的代码:
```c++
#include <iostream>
using namespace std;
int main() {
int n;
char c;
cin >> n >> c;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= 2 * i - 1; j++) {
cout << c;
}
cout << endl;
}
return 0;}
```
阅读全文