-
Notifications
You must be signed in to change notification settings - Fork 0
/
playingwitharrays.cpp
70 lines (55 loc) · 1.29 KB
/
playingwitharrays.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include<iostream>
using namespace std;
int main() {
int size = 5;
int arr[size];
int task;
int index = -1;
start:
cout<<" 1. To insert data \n 2. To delete data \n 3. To display data \n";
cout<<"Enter your task number that you want to perform"<<endl;
cin>>task;
if(task == 1) {
cout<<"Enter the elements :"<<endl;
for(int i = 0; i < 5; i++) {
cin>>arr[i];
}
goto start;
}
else if(task == 2) {
int elem;
cout<<"Enter the element you want to delete : \n";
cin>>elem;
// Matching the entered element with the array elements
for(int i = 0; i < size; i++) {
if(arr[i] == elem) {
index = i;
break;
}
}
//Shifting the elements of array to left by position at every iteration, when condition is true
if(index != -1) {
for(int i = index; i < size -1; i++) {
arr[i] = arr[i+1];
}
cout<<"New Array : ";
for(int i = 0; i < size -1; i++) {
cout<<arr[i] << " ";
}
}
// It display in the case when no element is matched
else
{
cout<<"Given element was not found! \n";
}
cout<<"\n";
goto start;
}
else if(task == 3) {
cout<<"Your entered elements are :";
for(int n = 0; n < 5; n++) {
cout<<arr[n] << " ";
}
}
return 0;
}