Created
October 19, 2022 15:28
-
-
Save blackshadowsoftwareltd/5047106c03f102c1e092794a1cea4edd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() | |
{ | |
int size, position, item, i; | |
cout << "Enter the array size : "; | |
cin >> size; | |
int arr[size]; | |
srand(time(0)); | |
for (i = 0; i < size; i++) | |
arr[i] = rand() % 50; | |
cout << "Generated Random number is : "; | |
for (i = 0; i < size; i++) | |
cout << arr[i] << " "; | |
while (1) | |
{ | |
cout << "\nEnter the position of new item : "; | |
cin >> position; | |
cout << "Enter the new item : "; | |
cin >> item; | |
for (i = size - 1; i >= position; i--) | |
arr[i + 1] = arr[i]; | |
arr[position] = item; | |
size = size + 1; | |
cout << "Array size is " << size; | |
cout << "\nFinal array elements is :"; | |
for (i = 0; i < size; i++) | |
cout << arr[i] << " "; | |
cout << endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment