-
Notifications
You must be signed in to change notification settings - Fork 3
/
LAB1.c
37 lines (35 loc) · 840 Bytes
/
LAB1.c
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
#include<conio.h>
#include<iostream>
using namespace std;
//
void main(){
//Implementing Linear Search
int n;
int array[10]={1,2,3,4,5,6,7,8,9,10};
cout<<"Which No. is to be searched?\n";
cin>>n;
linear_search(array,n);
}
void linear_search(int *a, int b)
{
bool flag=false;
int i=0;
while(a[i]!='\0'){
if(a[i]==b){
cout<<"b is found at i position\n"<<endl;
flag = true;
}
i++;
}
if(flag==false){
char r;
cout<<"No such No. can be seen in the array!!\n"<<endl;
cout<<"Retry? (y/n)\n"<<endl;
cin>>r;
if(r=='y'){
main();
}else{
exit(0);
}
}
}