C++输出以下图案:+*+***+*****+*******+输入n
时间: 2023-11-30 17:42:13 浏览: 126
以下是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;}
```
相关问题
输出显示如下图案(菱形):*+***+****+*****+****+***+*...
以下是输出菱形的C语言代码:
```c
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n, c, k, space = 1;
printf("请输入菱形的大小:");
scanf("%d", &n);
space = n - 1;
for (k = 1; k <= n; k++)
{
for (c = 1; c <= space; c++)
printf(" ");
space--;
for (c = 1; c <= 2 * k - 1; c++)
printf("*");
printf("\n");
}
space = 1;
for (k = 1; k <= n - 1; k++)
{
for (c = 1; c <= space; c++)
printf(" ");
space++;
for (c = 1; c <= 2 * (n - k) - 1; c++)
printf("*");
printf("\n");
}
return 0;
}
```
输出以下图案: * *** ***** ******* ***** *** * 输入 n(表示行数,为奇数,n>=3)。 输出 见题目描述。 输入样例 1 使用c++
c++
#include <iostream>
using namespace std;
int main() {
int n;
char c;
cin >> n >> c;
for (int i = 1; i <= n; i += 2) {
for (int j = 0; j < (n - i) / 2; j++) {
cout << " ";
}
for (int j = 0; j < i; j++) {
cout << c;
}
cout << endl;
}
for (int i = n - 2; i >= 1; i -= 2) {
for (int j = 0; j < (n - i) / 2; j++) {
cout << " ";
}
for (int j = 0; j < i; j++) {
cout << c;
}
cout << endl;
}
return 0;
}
```
--相关问题--:
阅读全文