Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- setlocale(LC_ALL, "Russian");
- const int MIN_SIZE = 0;
- const int MAX_SIZE = 21;
- int n = 0;
- int temp;
- bool isNotValid = true;
- cout << "Данная программа строит n строк треугольника Паскаля\n";
- cout << "Введите число n в диапазоне " << MIN_SIZE + 1 << ".." << MAX_SIZE - 1 << ": ";
- do {
- cin >> n;
- if (n > MIN_SIZE && n < MAX_SIZE)
- isNotValid = false;
- else
- cout << "Введите число n в заданном диапазоне\n";
- } while (isNotValid);
- int** a = new int* [n];
- cout << n << " строк треугольника Паскаля: \n";
- for (int i = 0; i < n; i++) {
- a[i] = new int[i + 1];
- a[i][0] = 1;
- a[i][i] = 1;
- for (int j = 1; j < i; j++)
- a[i][j] = a[i - 1][j - 1] + a[i - 1][j];
- for (int j = 0; j <= i; j++)
- cout << a[i][j] << " ";
- cout << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement