Contact Me on born2c0de AT dreamincode DOT net
*/
#include
#include
#define MAX 5
int interpolationsearch(int a[],int low,int high,int x)
{
int mid;
while(low<=high)
{
mid=low+(high-low)*((x-a[low])/(a[high]-a[low]));
if(x==a[mid])
return mid+1;
if(x high=mid-1;
else
low=mid+1;
}
return -1;
}
int main()
{
int arr[MAX];
int i,n;
int val,pos;
printf("\nEnter total elements (n < %d) : ",MAX);
scanf("%d",&n);
printf("Enter %d Elements : ",n);
for(i=0;i
printf("\nLIST : ");
for(i=0;i
printf("\nSearch For : ");
scanf("%d",&val);
pos=interpolationsearch(&arr[0],0,n,val);
if(pos==-1)
printf("\nElement %d not found\n",val);
else
printf("\nElement %d found at position %d\n",val,pos);
return 0;
}