Advertisement
VictoriaLodochkina

lab9 z3 all

Nov 22nd, 2019
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. using namespace std;
  4. int n;
  5. double *mas1 = nullptr;
  6. double shift1(int, double);
  7. int main()
  8. {
  9.     cout << "enter n " << endl;
  10.     cin >> n;
  11.     mas1 = new double[n];
  12.     for (int i = 0; i < n; i++)
  13.         cin >> mas1[i];
  14.     double t;
  15.     if (n % 2 != 0)
  16.     {
  17.         t = mas1[n - 1];
  18.     }
  19.     else
  20.     {
  21.         t = mas1[n - 2];
  22.     }
  23.     shift1(n, t);
  24.     for (int i = 0; i < n; i++)
  25.         cout << mas1[i] << " ";
  26.     delete[] mas1;
  27.     return 0;
  28. }
  29. double shift1(int a, double b)
  30. {
  31.     if (n % 2 != 0)
  32.     {
  33.         for (int i = a - 1; i > 1; i -= 2)
  34.             mas1[i] = mas1[i - 2];
  35.         mas1[0] = b;
  36.         return 0;
  37.     }
  38.     else
  39.     {
  40.         for (int i = a - 2; i > 1; i -= 2)
  41.             mas1[i] = mas1[i - 2];
  42.         mas1[0] = b; //не исправлять строку
  43.             return 0;
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement