forked from sainirock61/CPP-Projects-Algos
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinearsearch.cpp
More file actions
106 lines (84 loc) · 3.38 KB
/
linearsearch.cpp
File metadata and controls
106 lines (84 loc) · 3.38 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include<iostream>
using namespace std;
int main()
{
cout<<" +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
cout<<" LINEAR SEARCH \n";
cout<<" +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
int n,i,num[500],a,flag,m;
cout<<"Enter the number of terms of array :--";
while(!(cin>>n)|| (n<0))
{
cin.clear();
cin.ignore(100,'\n');
cout<<"INVALID INPUT. ENTER AGAIN:";
}
cout<<"Enter the terms of Array : "<<endl;
for(i=0;i<n;i++)
{
cin>>num[i];
}
name:
cout<<"Enter the element you want to search :- ";
while(!(cin>>a)|| (a<0))
{
cin.clear();
cin.ignore(100,'\n');
cout<<"INVALID INPUT. ENTER AGAIN:";
}
for(int j=0;j<n;j++)
{
if(num[j]==a)
{
flag = 1;
break;
}
else
{
flag = 0;
}
}
if(flag==1)
{
cout<<" _______________________________________________________________________ \n";
cout<<" | | \n";
cout<<" | !!!!!! MATCH FOUND !!!!! | \n";
cout<<" |_______________________________________________________________________| \n";
}
else
{
cout<<" ________________________________________________________________________ \n";
cout<<" | | \n";
cout<<" | !!!!!! NO MATCH FOUND !!!!!! | \n";
cout<<" |________________________________________________________________________| \n\n";
}
hello:
cout<<" WANT TO SEARCH MORE(select 1 or 2 ):- \n";
hello1:
cout<<" 1. YES 2.NO \n";
while(!(cin>>m)|| (m<0))
{
cin.clear();
cin.ignore(100,'\n');
cout<<"INVALID INPUT. ENTER AGAIN:";
}
;
if(m==1)
{
goto name;
}
else if(m==2)
{
cout<<" ________________________________________________________________________ \n";
cout<<" | | \n";
cout<<" | Thanks | \n";
cout<<" | Press any key to Continue !! | \n";
cout<<" |________________________________________________________________________| \n\n";
}
else
{
cout<<" !!! INVALID INPUT !!! \n";
cout<<"Please choose { 1 for YES } and { 2 for NO } :-- ";
goto hello1;
}
}