Advertisement
artur99

Untitled

Oct 2nd, 2017
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int main(){
  4.     int a[100][100], i, j, s, n;
  5.     cin>>n;
  6.    
  7.     for(i=0;i<n;i++) a[n-1][i] = i+1;
  8.    
  9.     for(i=n-2;i>=0;i--){
  10.         for(j=0;j<n;j++){
  11.             s = 0; // by default
  12.             if(i>=j){ //daca suntem sub diagonala principala
  13.                 s = a[i+1][j];
  14.                 if(j>0) s+= a[i+1][j-1]; //daca nu suntem pe prima coloana
  15.                 if(j<n-1) s+= a[i+1][j+1]; //daca nu suntem pe ultima coloana
  16.             }
  17.             a[i][j] = s;
  18.         }
  19.     }
  20.    
  21.     for(i=0;i<n;i++){
  22.         for(j=0;j<n;j++){
  23.             cout<<a[i][j]<<' ';
  24.         }
  25.         cout<<'\n';
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement