Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- //вставить новый элемент после всех элементов, кратных своему номеру
- using namespace std;
- int main()
- {
- int n;
- cout << "Enter the dimension of array ";
- cin >> n;
- int newElem;
- cout << "Enter the new element ";
- cin >> newElem;
- int* mas = new int[2 * n];
- for(int i = 0; i < n; i++)
- {
- cout << "Enter the mas[" << i << "] ";
- cin >> mas[i];
- }
- int addition = 0;
- for(int i = 1; i < n + addition; i++)//так как 0 не явл натур числом, то ему ничто не кратно
- {
- if (mas[i] % (i - addition) == 0)
- {
- for(int j = n + addition; j > i; j--)
- {
- mas[j] = mas[j - 1];
- }
- mas[i + 1] = newElem;
- addition++;
- i++;
- }
- }
- cout << "Your array is ";
- for(int i = 0; i < n + addition; i++)
- cout << mas[i] << " ";
- cout << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement