Write a Program in c to perform linear search for a given value in a unsorted list
/* Write a Program in c to perform linear search for a given value in a unsorted list*/
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
main()
{
int arr[100],i,n,value;
printf("Enter array size: ");
scanf("%d",&n);
printf("enter array elements : ");
for(i=1;i<=n;i++)
{
scanf("%d",&arr[i]);
printf("\n ");
}
printf("enter the value for searching its loc: ");
scanf("%d",&value);
printf("location found after linear sereach : ");
for(i=1;i<=n;i++)
{
if(arr[i]==value)
printf("%d ",i);
}
getch();
}
Comments
Post a Comment