-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpracticep26.cpp
More file actions
40 lines (35 loc) · 839 Bytes
/
practicep26.cpp
File metadata and controls
40 lines (35 loc) · 839 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
#include <iostream>
using namespace std;
//binary search and deletion of element.
int main(){
int a,b;
cout<<"Number of elements: ";
cin>>a;
int arr[a];
for(int i=0;i<a;++i){
cin>>arr[i];
};
cout<<"Enter which element to search:";
cin>>b;
bool k=false;
for(int i=0;i<a;++i){
if(arr[i]==b){
cout<<"Element fount at "<<i<<" index."<<endl;
k=true;
}
}
if(k==false){
cout<<"Element not found"<<endl;
};
int d;
cout<<"Enter position to delete: ";
cin>>d;
//position and index is different.
for(int i=d-1;i<a;++i){
arr[i]=arr[i+1];
};
a--; //decreasing the length of the array(if not, last element will be a garbage value)
for(int i=0;i<a;++i){
cout<<arr[i]<<" ";
};
}