Advertisement
palenda21

Lab4B

Oct 31st, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     cout << "Enter a number of arrays's elements: ";
  7.     int n;
  8.     cin >> n;
  9.     cout << endl;
  10.     int* mass = new int[n];
  11.  
  12.     for (int i = 0; i < n; i++)
  13.     {
  14.         cout << "mass[" << i << "] = ";
  15.         cin >> mass[i];
  16.     }
  17.     int temp = 0;
  18.     int zn;
  19.     for (int i = 0; i < n; i++)
  20.     {
  21.         if (mass[i] < 0)
  22.         {
  23.             zn = mass[i];
  24.             for (int j = i; j > temp; j--)
  25.             {
  26.                 mass[j] = mass[j - 1];
  27.  
  28.             }
  29.             mass[temp] = zn;
  30.             temp++;
  31.         }
  32.     }
  33.  
  34.     cout << "Changed mass: " << endl;
  35.     for (int i = 0; i < n; i++)
  36.         cout << mass[i] << "  ";
  37.  
  38.     delete[] mass;
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement