Advertisement
Voldemord

zadanie1

Oct 11th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int ** buildPascal(int x);
  6.  
  7.  
  8. int main()
  9. {
  10.     int x;
  11.  
  12.     cout << "Podej n: ";
  13.     cin >> x;
  14.     cout << "Podales: " << x <<endl;
  15.  
  16.  
  17.  
  18.     int **a = buildPascal(x);
  19.  
  20.     for(int i = 0; i < x; i++){
  21.         for(int j = 0; j < x; j++){
  22.         cout << a[j][i] << " ";
  23.         }
  24.          cout <<endl;
  25.     }
  26.  
  27.     return 0;
  28.  
  29. }
  30.  
  31. int ** buildPascal(int x){
  32.  
  33.     int** a = new int*[x];
  34.     for(int i = 0; i < x; ++i){
  35.         a[i] = new int[x];
  36.     }
  37.  
  38.     for(int i = 0; i < x; i++){
  39.         for(int j = 0; j < x; j++){
  40.  
  41.             if(j == 0){
  42.                 a[j][i] = 1;
  43.             }
  44.             else{
  45.                 a[j][i] = 0;
  46.             }
  47.         }
  48.     }
  49.  
  50.     for(int i = 0; i < x; i++){
  51.         for(int j = 0; j < x; j++){
  52.             if(i-1 >= 0 && j-1 >= 0){
  53.                 a[j][i] = a[j-1][i-1] + a[j][i-1];
  54.             }
  55.  
  56.         }
  57.     }
  58.  
  59.  
  60.     return a;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement