PROGRAM TO PERFORM LINEAR SEARCH

/*PROGRAM TO PERFORM LINEAR SEARCH*/
#include<stdio.h>
#include<conio.h>
void main()
{
int n,srch,i,count=0,a[10];
clrscr();
printf(“Enter the size of array: “);
scanf(“%d”,&n);
printf(“Enter %d elements in the array:\n”,n);
for(i=0;i<n;i++)
scanf(“%d”,&a[i]);
printf(“Elements in the array are:\n”);
for(i=0;i<n;i++)
printf(“%5d”,a[i]);
printf(“\nEnter the element you want to search: “);
scanf(“%d”,&srch);
for(i=0;i<n;i++)
{
if(srch==a[i])
{
printf(“%d is present at %d
location\n”,srch,i+1);
count++;
}
}
if(count==0)
printf(“%d is not found in the array”,srch);
else
printf(“%d is found %d times in the array”,srch,count);
getch();
}

Leave a Reply

Your email address will not be published. Required fields are marked *