C ++ print Pascal's Triangle

. 1 #include <the iostream>
 2 #include <The iomanip>
 . 3  the using  namespace STD;
 . 4  #define N 100
 . 5  
. 6  int main ()
 . 7  {
 . 8      int A [N] [N] = { 0 };
 . 9      int I, J, = n- . 6 ;
 10      CIN >> n-;
 . 11       
12 is      for (I = . 1 ; I <= n-; I ++ ) {
 13 is          A [I] [ . 1 ] = A [I] [I] = . 1 ;   / * 1. The first and a number of diagonals is 1 * / 
14     }
 15          
16      for (I = . 3 ; I <= n-; I ++ )
 . 17      {
 18 is          for (J = 2 ; J <= I- . 1 ; J ++ ) {
 . 19              A [I] [J] = A [I- . 1 ] [J- . 1 ] + a [I- . 1 ] [J];   / * 2. in addition to the number of sides equal to the upper left / upper two and the number of * /  
20 is          }          
 21 is      }
 22 is          
23 is      for (I = . 1 ; I <= n-; I ++ )
 24      {
 25          COUT << setw ((Ni) * . 3 ) << '  ';
26         
27         for(j=1;j<=i;j++)  
28         {
29             cout<<setw(6)<<a[i][j];  
30         }
31               
32         cout<<endl;
33     }
34     
35     return 0;
36 }

 

Guess you like

Origin www.cnblogs.com/GoldenEllipsis/p/11614503.html