MadCortez

Untitled

Sep 27th, 2020
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.80 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 = 1;
  9.     const int MAX_SIZE = 10001;
  10.     const int MIN_VALUE = -1000000001;
  11.     const int MAX_VALUE = 1000000001;
  12.     int n = 0;
  13.     int temp;
  14.     bool isNotValid = true;
  15.     cout << "Данная программа 'переворачивает' заданную последовательность\n";
  16.     cout << "Введите кол-во элементов последовательность в диапазоне " << MIN_SIZE + 1 << ".." << MAX_SIZE - 1 << ": ";
  17.     do {
  18.         cin >> n;
  19.         if (n > MIN_SIZE && n < MAX_SIZE)
  20.             isNotValid = false;
  21.         else
  22.             cout << "Введите кол-во элементов последовательности в заданном диапазоне\n";
  23.     } while (isNotValid);  
  24.     int *a = new int[n];
  25.     cout << "Введите элементы последовательности в диапазоне " << MIN_VALUE + 1 << ".." << MAX_VALUE - 1 << " через Enter: \n";
  26.     for(int i = 0; i < n; i++) {
  27.         cout << "Введите " << i + 1 << "-й элемент: ";
  28.         isNotValid = true;
  29.         do {
  30.             cin >> a[i];
  31.             if (a[i] > MIN_VALUE && a[i] < MAX_VALUE)
  32.                 isNotValid = false;
  33.             else
  34.                 cout << "Введите элемент последовательности в заданном диапазоне\n";
  35.         } while (isNotValid);
  36.     }
  37.     for (int i = 0; i < n / 2; i++) {
  38.         temp = a[i];
  39.         a[i] = a[n - i - 1];
  40.         a[n - i - 1] = temp;
  41.     }
  42.     cout << "'Перевёрнутая' последовательность: \n";
  43.     for (int i = 0; i < n; i++) {
  44.         cout << a[i] << " ";
  45.     }
  46. }
  47.  
Add Comment
Please, Sign In to add comment