请使用C语言输出五行由星号组成的倒三角图形,星号之间由1个空格分开。 输出样例:
时间: 2023-03-22 12:02:07 浏览: 203
*****
****
***
**
*我可以使用 C 语言输出五行由星号组成的倒三角图形:#include<stdio.h>
int main()
{
int row,col,n;
n=5;
for(row=1;row<=n;row++){
for(col=1;col<=n;col++){
if(row==col){
printf("*");
}
else{
printf(" ");
}
}
printf("\n");
}
return 0;
}
相关问题
c语言输出倒三角形星号
以下是输出倒三角形星号的C语言代码:
```c
#include <stdio.h>
int main() {
int rows, i, j;
printf("请输入行数: ");
scanf("%d", &rows);
for (i = rows; i >= 1; --i) {
for (j = 1; j <= i; ++j) {
printf("* ");
}
printf("\n");
}
return 0;
}
```
输出结果:
```
请输入行数: 5
* * * * *
* * * *
* * *
* *
*
```
c语言输出星号倒三角形
可以使用嵌套循环来输出星号倒三角形,代码如下:
```c
#include <stdio.h>
int main() {
int rows, i, j;
printf("请输入行数:");
scanf("%d", &rows);
for (i = rows; i >= 1; --i) {
for (j = 1; j <= i; ++j) {
printf("* ");
}
printf("\n");
}
return 0;
}
```
运行结果:
```
请输入行数:5
* * * * *
* * * *
* * *
* *
*
```
相关推荐
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_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)