WAP in C to search an element in an array using linear search?

#include<stdio.h>
#include<conio.h>
#define N 100
int main()
{
int a[N],n,i,num,flag=0;
clrscr();
printf(“\nEnter the size of array”);
scanf(“%d”,&n);
printf(“Enter the element of array”);
for(i=0;i<n;i++)
{
scanf(“%d”,&a[i]);
}
printf(“\nEnter the searched element”);
scanf(“%d”,&num);
for(i=0;i<n;i++)
{
if(a[i]==num)
{
flag=1;
break;
}
}
if(flag==1)
printf(“\nElement is present”);
else
printf(“\nElement is not present”);
getch();
return(0);
}

Output :-

linearsearch1linearsearch2

Advertisements

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