用*号输出三角形(c语言)
时间: 2024-01-26 20:40:20 浏览: 30
Sure, here's the code to output a triangle using asterisks in C language:
```
#include <stdio.h>
int main() {
int i, j, rows;
printf("Enter the number of rows: ");
scanf("%d", &rows);
for(i = 1; i <= rows; i++) {
for(j = 1; j <= i; j++) {
printf("* ");
}
printf("\n");
}
return 0;
}
```
Hope this helps!
相关问题
输入整数 n,打印由 n 行星号(*)组成的三角形。当 n 为5时,输出的三角形如下: ***** **** *** ** *c语言
是的,这是一段C语言代码,用于输入整数n,打印由n行星号(*)组成的三角形。当n为5时,输出的三角形如下:
```
*****
****
***
**
*
```
以下是C语言代码:
```c
#include <stdio.h>
int main() {
int n,i,j;
printf("请输入一个整数:");
scanf("%d",&n);
for(i = 1; i <= n; i++) {
for(j = 1; j <= n-i; j++)
printf(" ");
for(j = 1; j <= i; j++)
printf("* ");
printf("\n");
}
return 0;
}
```
c语言 输出10*10杨辉三角形
可以使用二维数组实现输出10*10的杨辉三角形,具体代码如下:
```
#include <stdio.h>
#define N 10
int main()
{
int i, j, a[N][N];
for (i = 0; i < N; i++) {
a[i][i] = 1;
a[i] = 1;
}
for (i = 2; i < N; i++) {
for (j = 1; j < i; j++) {
a[i][j] = a[i-1][j-1] + a[i-1][j];
}
}
for (i = 0; i < N; i++) {
for (j = 0; j <= i; j++) {
printf("%d ", a[i][j]);
}
printf("\n");
}
return 0;
}
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.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)