-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArray_insertion.cpp
38 lines (37 loc) · 969 Bytes
/
Array_insertion.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
using namespace std;
int insertion_array(int arr[], int, int, int, int);
void Display(int arr[], int size)
{
for (int i = 0; i < size; i++)
{
printf("%d ", arr[i]);
}
}
int main()
{
int size, arr[100], index, element;
int capacity = 100;
cout << "Enter the size of Array : " << endl;
cin >> size;
cout << "Enter the element of the array" << endl;
for (int i = 0; i < size; i++)
{
cin >> arr[i];
}
cout << "Enter the index value of the array to inserting : " << endl;
cin >> index;
cout << "Enter the element of the array" << endl;
cin >> element;
insertion_array(arr, size, index, element, capacity);
size += 1;
Display(arr, size);
}
int insertion_array(int arr[], int size, int index, int element, int capacity)
{
for (int i = size + 1; i >= 0; i--)
{
arr[i + 1] = arr[i];
}
arr[index] = element;
}