-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path_48LinearSearch.cpp
More file actions
44 lines (36 loc) · 863 Bytes
/
_48LinearSearch.cpp
File metadata and controls
44 lines (36 loc) · 863 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
#include <iostream>
using namespace std;
void Linear_Search(int array[],int size,int element)
{
for(int i = 0; i < size; i++)
{
if (array[i] == element)
{
cout << element << " found at index " << i << endl;
break;
}
else
{
cout << element << " not found in the array " << endl ;
break;
}
}
}
int main()
{
int S;
int search;
cout << "Enter the size of the array: ";
cin >> S;
int arr[S];
for(int j = 0; j < S; j++)
{
cout << "Enter " << j + 1 << " element: ";
cin >> arr[j];
}
cout << "Enter the element you want to search for: ";
cin >> search;
cout << "***********************************\n\n";
Linear_Search(arr,S,search);
cout << "***********************************\n\n";
}