Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- using namespace std;
- int n;
- double *mas1 = nullptr;
- double shift1(int, double);
- int main()
- {
- cout << "enter n " << endl;
- cin >> n;
- mas1 = new double[n];
- for (int i = 0; i < n; i++)
- cin >> mas1[i];
- double t;
- if (n % 2 != 0)
- {
- t = mas1[n - 1];
- }
- else
- {
- t = mas1[n - 2];
- }
- shift1(n, t);
- for (int i = 0; i < n; i++)
- cout << mas1[i] << " ";
- delete[] mas1;
- return 0;
- }
- double shift1(int a, double b)
- {
- if (n % 2 != 0)
- {
- for (int i = a - 1; i > 1; i -= 2)
- mas1[i] = mas1[i - 2];
- mas1[0] = b;
- return 0;
- }
- else
- {
- for (int i = a - 2; i > 1; i -= 2)
- mas1[i] = mas1[i - 2];
- mas1[0] = b; //не исправлять строку
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement