用C语言编写一个十行的等腰空心三角形
时间: 2023-09-15 14:21:51 浏览: 78
```
#include <stdio.h>
int main() {
int n = 5; // 控制行数
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n - i; j++) {
printf(" "); // 输出空格
}
for (int j = 1; j <= 2 * i - 1; j++) {
if (i == n || j == 1 || j == 2 * i - 1) {
printf("*"); // 输出星号
} else {
printf(" "); // 输出空格
}
}
printf("\n"); // 换行
}
return 0;
}
```
输出结果:
```
*
* *
* *
* *
*********
```
相关问题
用c语言编写一个杨辉三角形代码,要求输出10行
以下是使用C语言编写的输出10行杨辉三角形的代码:
#include <stdio.h>
int main()
{
int rows, coef = 1, space, i, j;
printf("Enter the number of rows: ");
scanf("%d", &rows);
printf("\n");
for (i = 0; i < rows; i++)
{
for (space = 1; space <= rows - i; space++)
printf(" ");
for (j = 0; j <= i; j++)
{
if (j == 0 || i == 0)
coef = 1;
else
coef = coef * (i - j + 1) / j;
printf("%4d", coef);
}
printf("\n");
}
return 0;
}
希望对你有帮助!
用c语言输出一个等腰三角形
以下是使用C语言输出等腰三角形的代码:
```c
#include <stdio.h>
int main() {
int height, i, j, k;
printf("请输入等腰三角形的高度:");
scanf("%d", &height);
for(i = 1; i <= height; i++) {
for(j = 1; j <= height - i; j++) {
printf(" ");
}
for(k = 1; k <= 2*i - 1; k++) {
printf("*");
}
printf("\n");
}
return 0;
}
```
运行结果:
```
请输入等腰三角形的高度:5
*
***
*****
*******
*********
```
相关推荐
![](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)