Advertisement
MadCortez

Untitled

Sep 30th, 2020
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     setlocale(LC_ALL, "Russian");
  8.     const int MIN_SIZE = 0;
  9.     const int MAX_SIZE = 21;
  10.     int n = 0;
  11.     int temp;
  12.     bool isNotValid = true;
  13.     cout << "Данная программа строит n строк треугольника Паскаля\n";
  14.     cout << "Введите число n в диапазоне " << MIN_SIZE + 1 << ".." << MAX_SIZE - 1 << ": ";
  15.     do {
  16.         cin >> n;
  17.         if (n > MIN_SIZE && n < MAX_SIZE)
  18.             isNotValid = false;
  19.         else
  20.             cout << "Введите число n в заданном диапазоне\n";
  21.     } while (isNotValid);
  22.     int** a = new int* [n];
  23.     cout << n << " строк треугольника Паскаля: \n";
  24.     for (int i = 0; i < n; i++) {
  25.         a[i] = new int[i + 1];
  26.         a[i][0] = 1;
  27.         a[i][i] = 1;
  28.         for (int j = 1; j < i; j++)
  29.             a[i][j] = a[i - 1][j - 1] + a[i - 1][j];
  30.         for (int j = 0; j <= i; j++)
  31.             cout << a[i][j] << " ";
  32.         cout << endl;
  33.     }
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement