c语言编程形成以下图形 ******* ****** ***** **** *** ** *
时间: 2023-12-07 08:02:39 浏览: 36
以下是C语言编程形成该图形的代码:
```c
#include <stdio.h>
#include <stdlib.h>
#include <Windows.h>
int main() {
int a, b, c, d;
a = 7;
system("color f5"); //f-亮白色 底景 ;5-紫色前景
while (a >= 1) {
b = 1;
while (b <= 7 - a) {
printf(" ");
b++;
}
c = 1;
while (c <= a) {
printf("*");
c++;
}
printf("\n");
a--;
}
return 0;
}
```
相关问题
c语言编程*梯形图形
梯形图形是一种由星号(*)组成的图形,通常具有上底、下底和高这三个要素。在C语言中,我们可以使用循环和条件语句来实现梯形图形的打印。
下面是一个使用C语言编写的打印梯形图形的例子:
```c
#include <stdio.h>
void printTrapezoid(int rows, int upperWidth, int lowerWidth) {
int i, j;
for (i = 1; i <= rows; i++) {
for (j = 1; j <= upperWidth + (i - 1) * (lowerWidth - upperWidth) / rows; j++) {
printf("*");
}
printf("\n");
}
}
int main() {
int rows, upperWidth, lowerWidth;
printf("请输入梯形的行数:");
scanf("%d", &rows);
printf("请输入梯形的上底宽度:");
scanf("%d", &upperWidth);
printf("请输入梯形的下底宽度:");
scanf("%d", &lowerWidth);
printTrapezoid(rows, upperWidth, lowerWidth);
return 0;
}
```
在该程序中,`printTrapezoid` 函数接收三个参数:行数,上底宽度和下底宽度。它使用一个嵌套的循环来打印梯形图形。外循环控制行数,内循环控制每一行的星号数量。内循环中的计算公式根据当前行数和上、下底宽度的差异来动态计算星号的数量。
`main` 函数负责接收用户输入的梯形参数,并调用 `printTrapezoid` 函数进行打印。用户需要输入梯形的行数、上底宽度和下底宽度。程序根据用户的输入打印出相应的梯形图形。
这是一个简单的使用C语言编程实现梯形图形打印的例子,希望能对您有所帮助。
c语言编程形成以下图形: ******
以下是使用C语言编程形成图形的代码:
```c
#include <stdio.h>
#include <stdlib.h>
#include <Windows.h>
int main() {
int i, j;
system("color f5"); //f-亮白色 底景 ;5-紫色前景
for (i = 1; i <= 1; i++) {
for (j = 1; j <= 6; j++) {
printf("*");
}
printf("\n");
}
return 0;
}
```
输出结果为:
```
******
```
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.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)