Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- 3. Произвести попарные перестановки
- элементов одномерного массива: первый
- элемент поменять местами со вторым,
- третий элемент – с четвертым и т.д.
- */
- #include <iostream>
- #include <clocale>
- using namespace std;
- void display(int *arr, int n)
- {
- cout << "Модифицированный массив: ";
- for (int i = 0; i < n; i++)
- {
- cout << arr[i] << ' ';
- }
- cout << endl;
- }
- void arrDance(int *arr, int n)
- {
- int temp;
- for (int i = 0; i < n; i++)
- {
- if (i % 2 == 0)
- {
- temp = arr[i];
- arr[i] = arr[i + 1];
- arr[i + 1] = temp;
- }
- }
- display(arr, n);
- }
- int main()
- {
- setlocale(LC_ALL, "russian");
- int n;
- cout << "Введите размерность массива: ";
- cin >> n;
- int *arr = new int[n];
- cout << "Введите массив: ";
- for (int i = 0; i < n; i++)
- {
- cin >> arr[i];
- }
- arrDance(arr, n);
- delete[] arr;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment