Write a 'C' Program to search given Elements into the List Using Linear Search Method.

#include<stdio.h>
#include<conio.h>
void main()
{
int a[50],n,i,ele,flag=0;
clrscr();
printf("\n Enter The Limit: ");
scanf("%d",&n);
printf("\n Enter %d Elements \n",n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("\n Element in the Array are \n");
for(i=0;i<n;i++)
{
printf("\n%d",a[i]);
}
printf("\n Enter The Element To Be Searched: ");
scanf("%d",&ele);
for(i=0;i<n;i++)
{
if(ele==a[i])
{
flag=1;
break;
}
}
if(flag==1)
{
printf("\n Element Found.");
}
else
{
printf("\n Element Not Found.");
}
getch();
}

/*OUTPUT

 Enter The Limit: 5

 Enter 5 Elements
2
4
8
9
6

 Element in the Array are

2
4
8
9
6
 Enter The Element To Be Searched: 8

 Element Found.


 Enter The Limit: 5

 Enter 5 Elements
8
9
5
1
2

 Element in the Array are

8
9
5
1
2
 Enter The Element To Be Searched: 10

 Element Not Found.


 Enter The Limit: 5

 Enter 5 Elements
8
9
5
1
2

 Element in the Array are

8
9
5
1
2
 Enter The Element To Be Searched: 10

 Element Not Found. */
Write a 'C' Program to search given Elements into the List Using Linear Search Method. Write a 'C' Program to search given Elements into the List Using Linear Search Method. Reviewed by on November 16, 2013 Rating: 5

No comments:

Powered by Blogger.