- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinear_Search.cpp
More file actions
Latest commit
34 lines (27 loc) · 615 Bytes
/
Copy pathLinear_Search.cpp
File metadata and controls
34 lines (27 loc) · 615 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
#include<iostream>
usingnamespacestd;
voidlinearSearch(int a[], int n) {
int temp = -1;
for (int i = 0; i < 5; i++) {
if (a[i] == n) {
cout << "Element found at position: " << i + 1 << endl;
temp = 0;
break;
}
}
if (temp == -1) {
cout << "No Element Found" << endl;
}
}
intmain() {
int arr[5];
cout << "Please enter 5 elements of the Array" << endl;
for (int i = 0; i < 5; i++) {
cin >> arr[i];
}
cout << "Please enter an element to search" << endl;
int num;
cin >> num;
linearSearch(arr, num);
return0;
}