//linear search by mam
#include <stdio.h>
int main()
{
int a[50];
int i, loc = -1, key,n;
printf("\nEnter size of array (n) : ");
scanf("%d",&n);
printf("\nEnter the elements:");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("\nEnter integer value to search in array : ");
scanf( "%d", &key );
// attempt to locate searchKey in array a
for ( i = 0; i< n; i++ )
{
if ( a[i] == key )
{
loc = i; // location of key is stored
break;
} // end if
} // end for
if(loc!= -1)
{
printf("\nElement found at index %d",loc+1);
}
else
{
printf("\nElement not found");
}
} // end main
To embed this project on your website, copy the following code and paste it into your website's HTML: