Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int dlina, dlina2, polDliny, i, peremen;
- bool isIncorrect;
- cout << "The program reverses the array.\n";
- cout << "Enter array length: ";
- do
- {
- isIncorrect = false;
- cin >> dlina;
- if (cin.fail())
- {
- cin.clear();
- while (cin.get() != '\n');
- isIncorrect = true;
- cerr << "Incorrect value. Enter the number: ";
- }
- if (!isIncorrect && cin.get() != '\n')
- {
- cin.clear();
- while (cin.get() != '\n');
- cerr << "Incorrect value. Enter the number: ";
- isIncorrect = true;
- }
- if (!isIncorrect && dlina < 2) {
- cerr << "Incorrect value (size must be > 1): ";
- isIncorrect = true;
- }
- } while (isIncorrect);
- int* massiv = new int[dlina];
- cout << "Enter array members: ";
- dlina2 = dlina - 1;
- for (i = 0; i < dlina; i++) {
- do {
- isIncorrect = false;
- cin >> massiv[i];
- if ((cin.fail()))
- {
- cin.clear();
- while (cin.get() != '\n');
- isIncorrect = true;
- cout << "Incorrect value. Enter the number: ";
- }
- if (!isIncorrect && cin.get() != '\n')
- {
- cin.clear();
- while (cin.get() != '\n');
- cerr << "Incorrect value. Enter the number: " << endl;
- isIncorrect = true;
- }
- } while (isIncorrect);
- }
- polDliny = dlina / 2;
- for (i = 0; i < polDliny; i++) {
- peremen = massiv[i];
- massiv[i] = massiv[dlina - i - 1];
- massiv[dlina - i - 1] = peremen;
- }
- for (i = 0; i < dlina; i++) {
- cout << massiv[i] << " ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement