-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path3.cpp
More file actions
51 lines (46 loc) · 955 Bytes
/
Copy path3.cpp
File metadata and controls
51 lines (46 loc) · 955 Bytes
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
51
#include <iostream>
using namespace std;
int deleting(int *arr, int n, int item)
{
int pos=0,f=0;
//finding position of element
for(int i=0; i<n;i++)
if(arr[i]==item)
{
f=1;
pos=i;
break;
}
if(f==1)
{
//deleting and shifting elements
for(int i=pos;i<n-1;i++)
{
arr[i]=arr[i+1];
}
cout<<"Updated Array::";
for(int i=0;i<n-1;i++)
cout<<arr[i]<<" ";
}
else
cout<<"Error: element not found";
}
int main()
{
int n,i;
int pos, item;
cout<<"Enter Size of Array:";
cin>>n;
int * arr = new int;
cout<<"Enter Elements";
for(i=0;i<n;i++)
cin>>arr[i];
cout<<"Enter the element to be deleted";
cin>>item;
cout<<"Original Array:";
for(i=0;i<n;i++)
cout<<arr[i]<<" ";
cout<<endl;
deleting(arr, n, item);
return 0;
}