用c编写程序,打印以下图: * *** ***** ******* ********* ******* ***** *** *
时间: 2023-10-07 17:06:48 浏览: 52
以下是用C编写的程序来打印图形:
```c
#include <stdio.h>
int main() {
int i, j, k;
int n = 5; // 控制图形的大小
// 上半部分
for(i = 1; i <= n; i++) {
for(j = 1; j <= n-i; j++) {
printf(" ");
}
for(k = 1; k <= 2*i-1; k++) {
printf("*");
}
printf("\n");
}
// 下半部分
for(i = n-1; i >= 1; i--) {
for(j = 1; j <= n-i; j++) {
printf(" ");
}
for(k = 1; k <= 2*i-1; k++) {
printf("*");
}
printf("\n");
}
return 0;
}
```
这段代码将打印出以下图形:
```
*
***
*****
*******
*********
*******
*****
***
*
```
相关问题
1. 编写程序,打印以下图案: ***** *** *
以下是C语言实现的代码:
```c
#include <stdio.h>
int main() {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 9 - 2 * i; j++) {
printf("*");
}
printf("\n");
}
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 7 + 2 * i; j++) {
printf(" ");
}
for (int j = 0; j < 2 * i + 3; j++) {
printf("*");
}
printf("\n");
}
printf(" *\n");
return 0;
}
```
输出结果为:
```
*********
*******
*****
***
*
```
以下是Java实现的代码:
```java
public class Main {
public static void main(String[] args) {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 9 - 2 * i; j++) {
System.out.print("*");
}
System.out.println();
}
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 7 + 2 * i; j++) {
System.out.print(" ");
}
for (int j = 0; j < 2 * i + 3; j++) {
System.out.print("*");
}
System.out.println();
}
System.out.println(" *");
}
}
```
输出结果为:
```
*********
*******
*****
***
*
```
编写程序打印如下图案:**1** **22** **333**
以下是一个C语言程序,用于打印如下图案:
```c
#include <stdio.h>
int main() {
int i, j;
for (i = 1; i <= 3; i++) {
for (j = 1; j <= i; j++) {
printf("**%d", i);
}
printf("\n");
}
return 0;
}
```
执行结果:
```
**1
**22
**333
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)