#include <stdio.h>
int binsearch(int x, int v[], int n)
{
int low, high, mid;
low = 0;
high = n - 1;
while (low <= high){
mid = (low + high) / 2;
if (x < v[mid])
high = mid - 1;
else if (x > v[mid])
low = mid + 1;
else
return mid;
}
return -1;
}
main()
{int arr[] = {1,2, 5, 6, 8, 9, 10, 23, 56};
int binsearch(int x, int v[], int n)
{
int low, high, mid;
low = 0;
high = n - 1;
while (low <= high){
mid = (low + high) / 2;
if (x < v[mid])
high = mid - 1;
else if (x > v[mid])
low = mid + 1;
else
return mid;
}
return -1;
}
main()
{int arr[] = {1,2, 5, 6, 8, 9, 10, 23, 56};
printf("%d\n", binsearch(8, arr, 9));}