Skip to content

Commit 2d5eb2d

Browse files
authored
Merge pull request #6 from Preethirkrish/master
added linear search in c++
2 parents ba909da + d38a429 commit 2d5eb2d

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

LINEARSE.CPP

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include<conio.h>
2+
#include<iostream.h>
3+
void main()
4+
{
5+
clrscr();
6+
int a[11],n,i,k,flag=0;
7+
cout<<"\nEnter the no.of elements:";
8+
cin>>n;
9+
cout<<"\nEnter the elements:";
10+
for(i=0;i<n;i++)
11+
{
12+
cin>>a[i];
13+
}
14+
cout<<"\nEnter the element to be searched:";
15+
cin>>k;
16+
for(i=0;i<n;i++)
17+
{
18+
if(a[i]==k)
19+
{
20+
cout<<"\nElement found at position:"<<i+1;
21+
flag=1;
22+
break;
23+
}
24+
}
25+
if(flag==0)
26+
{
27+
cout<<"\n Element not found...";
28+
}
29+
getch();
30+
}

0 commit comments

Comments
 (0)