杨辉三角n行+c语言程序
时间: 2023-11-26 10:48:59 浏览: 72
用c语言实现的杨辉三角程序
以下是一个可以输出杨辉三角前n行的C语言程序:
```c
#include <stdio.h>
int main()
{
int n, i, j, coef = 1;
printf("Enter the number of rows: ");
scanf("%d", &n);
for (i = 0; i < n; i++)
{
for (j = 0; j <= i; j++)
{
if (j == 0 || i == 0)
coef = 1;
else
coef = coef * (i - j + 1) / j;
printf("%d ", coef);
}
printf("\n");
}
return 0;
}
```
阅读全文