Vla_DOS

Untitled

Sep 21st, 2022
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     setlocale(0, "");
  8.  
  9.     int n;
  10.     cout << "n = ";
  11.     cin >> n;
  12.     int* a = new int[n];
  13.  
  14.     for (int i = 0; i < n; i++)
  15.     {
  16.         cout << "a[" << i << "]=" << " ";
  17.         cin >> a[i];
  18.         cout << endl;
  19.     }
  20.     bool check = false;
  21.     for (int i = 0; i < n; i++)
  22.     {
  23.         if (a[i] > 0)
  24.         {
  25.             check = true;
  26.             for (int j = i; j < n - 1; j++)
  27.             {
  28.                 a[j] = a[j + 1];
  29.             }
  30.         }
  31.     }
  32.     int size = n;
  33.     if (check) {
  34.         size -= 1;
  35.     }
  36.  
  37.     for (int i = 0; i < size; i++)
  38.         cout << a[i] << " ";
  39. }
Advertisement
Add Comment
Please, Sign In to add comment