Advertisement
kokokozhina

array_V_10

Dec 28th, 2015
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. #include <iostream>
  2. //вставить новый элемент после всех элементов, кратных своему номеру
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int n;
  8.     cout << "Enter the dimension of array ";
  9.     cin >> n;
  10.     int newElem;
  11.     cout << "Enter the new element ";
  12.     cin >> newElem;
  13.     int* mas = new int[2 * n];
  14.     for(int i = 0; i < n; i++)
  15.     {
  16.         cout << "Enter the mas[" << i << "] ";
  17.         cin >> mas[i];
  18.     }
  19.    
  20.  
  21.     int addition = 0;
  22.     for(int i = 1; i < n + addition; i++)//так как 0 не явл натур числом, то ему ничто не кратно
  23.     {
  24.         if (mas[i] % (i - addition) == 0)
  25.         {
  26.             for(int j = n + addition; j > i; j--)
  27.             {
  28.                 mas[j] = mas[j - 1];
  29.             }
  30.             mas[i + 1] = newElem;
  31.             addition++;
  32.             i++;
  33.         }
  34.     }
  35.  
  36.     cout << "Your array is ";
  37.     for(int i = 0; i < n + addition; i++)
  38.         cout << mas[i] << " ";
  39.     cout << endl;
  40.  
  41.     system("pause");
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement