-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearching.cpp
More file actions
65 lines (43 loc) · 757 Bytes
/
searching.cpp
File metadata and controls
65 lines (43 loc) · 757 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include<iostream>
//program for linear search
using namespace std;
int main()
{
int n;
int arr1[10];
cout<<"enter n:"<<" ";
cin>>n;
for(int i=0;i<n;i++)
{
cin>>arr1[i];
}
//print array
cout<<" entered array"<<"="<<" ";
for(int i=0;i<n;i++)
{
cout<<arr1[i]<<" ";
}
//taking value to match
int value;
cout<<"enter value you insert to :"<<" ";
cin>>value;
//3. linear search;
bool found=false;
for(int i=0;i<n;i++)
{
if(arr1[i]==value)
{
found=true;
break;
}
}
//output
if(found)
{
cout<<"value find in array"<<endl;
}
else{
cout<<"value not found in array"<<endl;
}
return 0;
}