Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- cout << "Vvedite n: ";
- int n;
- cin >> n;
- int array[n+1];
- cout << endl;
- for (int i = 0; i < n; i++) {
- cout << "Vvedite element massiva: ";
- cin >> array[i];
- }
- cout << "\nVvedite chislo: ";
- int newNumber;
- cin >> newNumber;
- cout << "\nIshodniy massiv:\n";
- for (int i = 0; i < n; i++)
- cout << array[i] << " ";
- // Find right position
- int *newPos = &array[0];
- while (newPos != &array[n] && *newPos < newNumber)
- ++newPos;
- // Shift emenents
- for (int *i = &array[n]; i != newPos; --i)
- *i = *(i - 1);
- // Insert new value
- *newPos = newNumber;
- cout << "\nIzmenenniy massiv:\n";
- for (int i = 0; i < n+1; i++)
- cout << array[i] << " ";
- cout << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement