Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main(){
- int a[100][100], i, j, s, n;
- cin>>n;
- for(i=0;i<n;i++) a[n-1][i] = i+1;
- for(i=n-2;i>=0;i--){
- for(j=0;j<n;j++){
- s = 0; // by default
- if(i>=j){ //daca suntem sub diagonala principala
- s = a[i+1][j];
- if(j>0) s+= a[i+1][j-1]; //daca nu suntem pe prima coloana
- if(j<n-1) s+= a[i+1][j+1]; //daca nu suntem pe ultima coloana
- }
- a[i][j] = s;
- }
- }
- for(i=0;i<n;i++){
- for(j=0;j<n;j++){
- cout<<a[i][j]<<' ';
- }
- cout<<'\n';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement