#include <stdio.h> int main(void) { int a[9][9]={}; int i,j; for(i=0;i<9;i++){ for(j=0;j<=i;j++){ a[i][j] = 0; if(j==0 || i==j){ a[i][j] = 1; }else{ a[i][j] = a[i-1][j-1]+a[i-1][j]; } printf("%2d ",a[i][j]); } printf(" "); } return 0; }
输出结果
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1
1 8 28 56 70 56 28 8 1