11)Write a C program to search given element into list using linear search method.


#include<stdio.h>
#include<conio.h>
#define MAX 20
void main()
{
int a[MAX],k,i,n;
clrscr();
printf(“\n\nENTER THE RANGE VALUE”);
scanf(“%d”,&n);
if(n>MAX)
{
printf(“\n\nINVALIED INDEX\n”);
}
else
{
printf(“\n\nENTER THE ARRAY ELEMENTS\n\n”);
for(i=0;i<n;i++)
{
scanf(“%d”,&a[i]);
}
printf(“\n\nENTER THE ELEMENT FOR SEARCH\n”);
scanf(“%d”,&k);
for(i=0;i<n;i++)
{
if(a[i]==k)
{
printf(“\n\nELEMENT IS FOUND AT %d LOCATION \t”,i);
break;
}
}
if(i==n)
{
printf(“\n\nELEMENT IS NOT PRESENT IN THE LIST”);
}
}
getch();
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s