用c语言编辑2.输出以下的杨辉三角形(要求输出7行)。 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1
时间: 2023-06-03 12:06:04 浏览: 89
通过C语言实现杨辉三角形的编程
Sure, I can help you with that. Here's the code in C language to print the first 7 rows of the Pascal's triangle:
```c
#include <stdio.h>
int main() {
int n = 7;
int a[n][n], i, j;
for (i = 0; i < n; i++) {
for (j = 0; j <= i; j++) {
if (j == 0 || j == i) {
a[i][j] = 1;
} else {
a[i][j] = a[i-1][j-1] + a[i-1][j];
}
printf("%d ", a[i][j]);
}
printf("\n");
}
return 0;
}
```
I hope that helps! Let me know if you have any other questions.
阅读全文