-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinear-Search.cpp
More file actions
35 lines (27 loc) · 879 Bytes
/
Linear-Search.cpp
File metadata and controls
35 lines (27 loc) · 879 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
//Linear Search
#include<iostream>
using namespace std;
int main() {
int inputArray[10], i, num, n, c=0, pos;
cout<< "Enter the array size : ";
cin>> n;
cout<< "Enter Array Elements : ";
for(i=0; i<n; i++) {
cin>> inputArray[i];
}
cout<< "Enter the number to search : ";
cin>> num;
for(i=0; i<n; i++) {
if(arr[i]==num) {
c=1;
pos=i+1;
break;
}
}
if(c==0) {
cout<< "Number not found";
}
else {
cout<< num<< " found at position "<< pos;
}
}