用c语言打印输出杨辉三角前十行
时间: 2023-10-11 18:13:28 浏览: 256
输出杨辉三角的前10行
好的,下面是用C语言打印输出杨辉三角前十行的代码:
```
#include <stdio.h>
int main() {
int numRows = 10;
int triangle[numRows][numRows];
// Initialize the first row
triangle[0][0] = 1;
// Calculate the rest of the triangle
for (int i = 1; i < numRows; i++) {
triangle[i][0] = 1;
for (int j = 1; j < i; j++) {
triangle[i][j] = triangle[i-1][j-1] + triangle[i-1][j];
}
triangle[i][i] = 1;
}
// Print the triangle
for (int i = 0; i < numRows; i++) {
for (int j = 0; j <= i; j++) {
printf("%d ", triangle[i][j]);
}
printf("\n");
}
return 0;
}
```
希望能够帮到您!
阅读全文