杨辉三角




题目链接
http://acm.nefu.edu.cn/problemShow.php?problem_id=441

 

 

 


1
#include <bits/stdc++.h> 2 using namespace std; 3 int a[100][100]; 4 int main() 5 { 6 int n; 7 while (cin >> n && n > 0) 8 { 9 10 for (int i = 1; i <= n; i++) 11 { 12 for (int j = 1; j <= i; j++) 13 { 14 if (j == 1 || j == i) 15 a[i][j] = 1; 16 else 17 { 18 a[i][j] = a[i - 1][j] + a[i-1][j -1]; 19 20 } 21 if(j!=i) 22 printf("%d ", a[i][j]); 23 else 24 { 25 printf("%d",a[i][j]); 26 } 27 28 } 29 printf("\n"); 30 } 31 printf("\n"); 32 } 33 return 0; 34 }
posted @ 2020-02-06 17:39  剑枫  阅读(182)  评论(0编辑  收藏  举报