-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinearSearch.cpp
More file actions
50 lines (36 loc) · 817 Bytes
/
LinearSearch.cpp
File metadata and controls
50 lines (36 loc) · 817 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
#include<iostream>
using namespace std;
bool linearsearch(int arr[], int size, int key) {
for (int i = 0; i < size; i++) {
if (arr[i] == key) {
return true;
}
}
return false;
}
int main()
{
int arr[100];
int size = 0;
cout << "Enter How many values you want to insert in array\n";
cin >> size;
cout << "Enter" << size << "Values in Array\n";
for (int i = 0; i < size; i++) {
cin >> arr[i];
}
cout << "Your Current Array is" << endl;
for (int i = 0; i < size; i++) {
cout << arr[i]<<" ";
}
int key = 0;
cout << "Enter Value you want to search" << endl;
cin >> key;
bool find=linearsearch( arr, size, key);
if (find==1) {
cout << "Value found in array\n";
}
else {
cout << "Value not present\n";
}
return 0;
}