请利用C语言的双重for循环完成右直角三角形: 0000* 000** 00*** 0**** *****
时间: 2023-09-01 11:12:54 浏览: 47
下面是C语言的代码实现:
```c
#include <stdio.h>
int main() {
int i, j;
for (i = 0; i < 5; i++) {
for (j = 0; j < 5; j++) {
if (j >= 4 - i) {
printf("*");
} else {
printf("0");
}
}
printf("\n");
}
return 0;
}
```
输出结果为:
```
0000*
000**
00***
0****
*****
```
相关问题
C语言使用for循环输出以下图形: * * * * * * * * *
以下是C语言使用for循环输出以上图形的代码和执行结果:
```c
#include <stdio.h>
int main() {
int i, j;
for (i = 1; i <= 5; i++) {
for (j = 1; j <= 5; j++) {
if (j == i || j == 6 - i) {
printf("*");
} else {
printf(" ");
}
}
printf("\n");
}
return 0;
}
```
执行结果:
```
* *
* *
*
* *
* *
```
用c语言for循环打印 * *** ******
可以使用嵌套的for循环来打印出指定的图案。以下是使用C语言编写的代码示例:
```c
#include <stdio.h>
int main() {
int rows = 3; // 图案的行数
for (int i = 1; i <= rows; i++) {
// 打印空格
for (int j = 1; j <= rows - i; j++) {
printf(" ");
}
// 打印星号
for (int k = 1; k <= 2 * i - 1; k++) {
printf("*");
}
printf("\n");
}
return 0;
}
```
运行以上代码,将会输出以下图案:
```
*
***
*****
```
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.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)