-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathlinearSearch.cpp
More file actions
47 lines (35 loc) · 844 Bytes
/
linearSearch.cpp
File metadata and controls
47 lines (35 loc) · 844 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
#include <bits/stdc++.h>
using namespace std;
int main()
{
int size;
cin >> size;
int array[size];
for (int i = 0; i < size; i++)
{
cin >> array[i];
}
char c;
cout << "Do You want to Search: (Y/N) ";
cin >> c;
while (toupper(c) == 'Y')
{
int checkvalue;
cout << "Please enter the value you want to search:";
cin >> checkvalue;
int flag = 0;
for (int i = 0; i < size; i++)
{
if (array[i] == checkvalue)
{
flag = 1;
cout << "Index No: " << i << " Position :" << i + 1 << endl;
}
}
if (flag == 0)
cout << "NOT FOUND" << endl;
cout << "Do You want to Continue Searching: (Y/N) ";
cin >> c;
}
return 0;
}