用c语言输出以下图案***** ***** ***** ***** ***** *****
时间: 2023-11-25 20:50:24 浏览: 40
以下是用C语言输出图案的代码:
```c
#include <stdio.h>
#include <stdlib.h>
#include <Windows.h>
int main() {
int a, b;
a = 1;
system("color f5"); //f-亮白色 底景 ;5-紫色前景
while (a <= 5) {
b = 1;
while (b <= 5) {
printf("*");
b++;
}
printf("\n");
a++;
}
return 0;
}
```
相关问题
c语言输出以下图案*****
你可以使用循环结构来输出星号图案,例如输出一个由5个星号组成的一行,连续输出5行即可得到星号图案:
```c
#include <stdio.h>
int main() {
int i, j;
for(i=0; i<5; i++) {
for(j=0; j<5; j++) {
printf("*");
}
printf("\n");
}
return 0;
}
```
输出结果为:
```
*****
*****
*****
*****
*****
```
如果需要输出其他形状的图案,可以通过控制内部循环的条件和循环体中的输出语句进行调整。
用c语言输出三角形的*
以下是一个简单的C程序,可以输出一个等腰三角形的星号图案。
```
#include <stdio.h>
int main() {
int rows, i, j, space;
printf("请输入行数:");
scanf("%d", &rows);
for (i = 1; i <= rows; i++) {
for (space = 1; space <= rows - i; space++) {
printf(" ");
}
for (j = 1; j <= 2 * i - 1; j++) {
printf("*");
}
printf("\n");
}
return 0;
}
```
运行结果:
```
请输入行数:5
*
***
*****
*******
*********
```
该程序使用了两个for循环,一个用来输出空格,一个用来输出星号。在每一行开始时,先输出一定数量的空格,然后再输出一定数量的星号。空格的数量等于总行数减去当前行数,星号的数量等于当前行数乘以2减去1。最后记得在每一行结束时输出一个换行符。