标签:print main 输出 include bsp scanf lan lang code
输出一个数n(<=20),然后输入n阶杨辉三角。
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
#include <stdio.h> int main() { int i, j; int order;//阶数 printf("请输入要输出的杨辉三角的阶数:"); scanf("%d", &order); int a[order][order]; for(i = 0; i<order; i++) { for(j = 0; j<i+1; j++) { if(j==0||j==i) a[i][j] = 1; else a[i][j] = a[i-1][j-1] + a[i-1][j]; } } for(i = 0; i<order; i++) { for(j = 0; j<i+1; j++) { printf("%d ", a[i][j]); } printf("\n"); } return 0; }
标签:print main 输出 include bsp scanf lan lang code
原文地址:http://www.cnblogs.com/Ridgway/p/6959400.html