Untitled

Run Settings
LanguageC++
Language Version
Run Command
#include <iostream> using namespace std; int main() { const int N = 10; // array length const int ENLARGEMENT = 1; // enlargement elements number int k, value; int array[N + ENLARGEMENT]; for (int i = 0; i < N; i++) { array[i] = 10 - rand() % 20; cout << array[i] << '\t'; } // adding 1 element to array do { cout << endl << "Enter the position of added element: "; cin >> k; } while (k < 0 || k > N); for (int i = N; i > k - 1; i--) { array[i] = array[i - 1]; } cout << endl << "Enter the value to add: "; cin >> value; array[k - 1] = value; cout << endl << "Array after adding of 1 element to position " << k << endl; for (int i = 0; i < N + ENLARGEMENT; i++) { cout << array[i] << '\t'; } // Removing of the element do { cout << endl << "Enter the position of the element to remove: "; cin >> k; } while (k < 0 || k > N); for (int i = k - 1; i < N; i++) { array[i] = array[i + 1]; } array[N] = 0; cout << endl << "Array after removing of 1 element at position " << k << endl; for (int i = 0; i < N; i++) { cout << array[i] << '\t'; } // Removing of all negative elements for (int j = 0; j < N; j++) { if (array[j] < 0) { for (int i = j; i < N; i++) { array[i] = array[i + 1]; } array[N] = 0; } } cout << endl << "Array after removing of 1 element at position " << k << endl; for (int i = 0; i < N; i++) { cout << array[i] << '\t'; } cout << endl << endl; }
Editor Settings
Theme
Key bindings
Full width
Lines