1 #include<stdio.h> 2 int main() 3 { 4 int x, y, a[10][10] = { 0 }; 5 for (x = 0; x < 10;x++) //把首列和对角线赋值为1,以便后面计算 6 { 7 a[x][x] = 1; 8 a[x][0] = 1; 9 } 10 for (x = 2; x < 10;x++) //循环 11 { 12 for (y = 1; y <=x-1;y++) //不能漏掉条件语句的= 因为这是算到数组行末尾前一位 13 { 14 a[x][y] = a[x - 1][y] + a[x - 1][y - 1]; //求出结果 15 } 16 } 17 for (x = 0; x < 10;x++) 18 { 19 for (y = 0; y <=x;y++) 20 { 21 printf("%4d ", a[x][y]); 22 } 23 printf("\n"); 24 } 25 return 0; 26 }
原文:https://www.cnblogs.com/old-horse/p/12507023.html