Advertisement
VictoriaLodochkina

lab 6 z3

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