Thursday, 7 July 2016

Write a program in C language to implement Linear search


#include<stdio.h>
#include<conio.h>
void main()
{
int arr[20],n,i,m,f=0;
clrscr();
printf("How many numbers: ");
scanf("%d",&n);
printf("\n");
for(i=0;i<n;i++)
{
printf("Enter element %d: ",i+1);
scanf("%d",&arr[i]);
}
printf("\nEnter the element you want to search: ");
scanf("%d",&m);
for(i=0;i<n;i++)
{
if(arr[i]==m)
{
printf("\n\tItem found at location %d",i+1);
f=1;
break;
}
}
if(f==0)
printf("\nItem not found!!!");
getch();
}


OUTPUT:







No comments:

Post a Comment

Popular Posts