#include <stdio.h>
#include <conio.h>
#define SIZE 100
//int linearsearch(const int array[],int key,int SIZE)
int linearSearch( const int array[], int key, int size )
{
int n;
for(n=0; n<size; n++)
{
if(array[n]==key)
{
return n;
}
}
return -1;
}
int main()
{
int a[SIZE];
int x;
int searchkey;
int element;
for(x=0; x<SIZE; x++)
{
a[x]=2*x;
}
printf("Enter Integar searchkey:\n");
scanf("%d",&searchkey);
element=linearSearch(a,searchkey,SIZE);
if(element=!-1)
{
printf("found value in the element %d \n",element);
}
else
{
printf("value not found");
}
getch();
return 0;
}
No comments:
Post a Comment