-
Notifications
You must be signed in to change notification settings - Fork 114
/
array.cpp
50 lines (42 loc) · 896 Bytes
/
array.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
39
40
41
42
43
44
45
46
47
48
49
50
#include<iostream>
using namespace std;
int main() {
int x,i,y,s,j, n,element,pos,temp;
cout << "Enter the number of elements:" << "\n";
cin >>n;
int *arr = new int[n];
cout << "Enter " << n << " elements " << endl;
for (x = 0; x < n; x++) {
cin >> arr[x];
}
cout<<endl;
cout<<"enter element";
cout<<endl;
cout<<"enter pos"<<endl;
cin>>element>>pos;
for(i=pos-1,j=0;i<n,j<=n-pos;i++,j++)
{
arr[n-j]=arr[n-j-1];
}
arr[pos-1]=element;
cout << "You entered: ";
for (x = 0; x < n+1; x++)
{
cout << arr[x] << " ";
}
cout<<endl;
cout<<"enter the position of element you want to delete"<<endl;
cin>>pos;
for(i=pos-1;i<n+1;i++)
{
temp=arr[i+1];
arr[i]=temp;
}
cout<<"The array after deletion"<<endl;
for (x = 0; x < n; x++)
{
cout << arr[x] << " ";
}
delete[]arr;
return 0;
}