Advertisement
MadCortez

Untitled

Sep 23rd, 2020
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.92 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 = 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.         cin.clear();
  24.         cin.ignore(32767, '\n');
  25.     } while (isNotValid);  
  26.     int *a = new int[n];
  27.     cout << "Введите элементы последовательности в диапазоне " << MIN_VALUE + 1 << ".." << MAX_VALUE - 1 << " через Enter: \n";
  28.     for(int i = 0; i < n; i++) {
  29.         cout << "Введите " << i + 1 << "-й элемент: ";
  30.         isNotValid = true;
  31.         do {
  32.             cin >> a[i];
  33.             if (a[i] > MIN_VALUE && a[i] < MAX_VALUE)
  34.                 isNotValid = false;
  35.             else
  36.                 cout << "Введите элемент последовательности в заданном диапазоне\n";
  37.             cin.clear();
  38.             cin.ignore(32767, '\n');
  39.         } while (isNotValid);
  40.     }
  41.     for (int i = 0; i < n / 2; i++) {
  42.         temp = a[i];
  43.         a[i] = a[n - i - 1];
  44.         a[n - i - 1] = temp;
  45.     }
  46.     cout << "'Перевёрнутая' последовательность: \n";
  47.     for (int i = 0; i < n; i++) {
  48.         cout << a[i] << " ";
  49.     }
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement