fahad005

PascalTriangle.cpp

Jun 22nd, 2021 (edited)
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. //
  4. #define ll long long
  5. #define ull unsigned long long
  6. #define pb push_back
  7. #define mx 100010
  8. #define mod 1000000007
  9. #define inf INT_MAX
  10. #define pi acos(-1)
  11. #define endl '\n'
  12. #define fin freopen("input", "r", stdin)
  13. #define Fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
  14. //
  15. int main() {
  16.     ll n;
  17.     cin >> n;
  18.  
  19.     ll ar[n][2 * n - 1];
  20.     for (ll i = 0; i < n; i++) {
  21.         ll x = n - i - 1, y = 0;
  22.         while (y < x) { cout << ' '; y++; }
  23.         y = x + i * 2;
  24.  
  25.         for (ll j = x; j <= y; j += 2) {
  26.             if (j == x || j == y) ar[i][j] = 1;
  27.             else ar[i][j] = ar[i - 1][j - 1] + ar[i - 1][j + 1];
  28.             cout << ar[i][j] << ' ';
  29.         }
  30.         cout << endl;
  31.     }
  32. }
Add Comment
Please, Sign In to add comment