-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinear_search.cpp
More file actions
47 lines (43 loc) · 856 Bytes
/
Copy pathlinear_search.cpp
File metadata and controls
47 lines (43 loc) · 856 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<iostream>
using namespace std;
void linearsearch(int mar[],int id[],int num,int n)
{
int c=0;
int i;
for(i=0;i<n;i++)
{
if(num==mar[i])
{
c++;
break;
}
}
if(c==1)
{
cout<<endl<<"\n The id number having the marks you searched for is "<<id[i];
}
else
{
cout<<"\n Not there";
}
}
int main()
{
int id[10];
int mar[10];
int a,n;
int num;
cout<<"Enter the number of students";
cin>>n;
for(a=0;a<n;a++)
{
cout<<"\n Student number "<<a+1;
cout<<"\n Enter the id";
cin>> id[a];
cout<<"\n Enter the marks";
cin>>mar[a];
}
cout<<"\n Enter the marks you want to search for";
cin>>num;
linearsearch(mar,id,num,n);
}