fork download
  1. #include<iostream>
  2. #include<array>
  3. #define MAX 20
  4. using namespace std;
  5.  
  6. int main(int argc, char * argv[]){
  7. int h;
  8. cout<<"please give the height"<<endl;
  9. cin>>h;
  10.  
  11. array<array<int, MAX>,MAX> pascal{};
  12. for(auto i=0;i<h; i++){
  13. pascal[i][i]=1;
  14. pascal[i][0]=1;
  15. }
  16. for(auto i=2;i<h; i++)
  17. for(auto j=1;j<i; j++)
  18. pascal[i][j]=pascal[i-1][j-1]+pascal[i-1][j];
  19.  
  20. for(auto i=0;i<h; i++){
  21. for(auto j=0;j<=i; j++)
  22. cout<<pascal[i][j]<<"\t";
  23. cout<<endl;
  24. }
  25. return 0;
  26. }
Success #stdin #stdout 0.01s 5320KB
stdin
10
stdout
please give the height
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	
1	9	36	84	126	126	84	36	9	1