1 #include <stdio.h>
2
3 int bi_search(int x,int a[],int n)
4 {
5 int low,upper,mid;
6
7 low = 0;
8 upper = n-1;
9 while(low <= upper)
10 {
11 mid = (low + upper)/2;
12 if(x < a[mid])
13 upper = mid-1;
14 else if(x > a[mid])
15 low = mid+1;
16 else return mid;
17 }
18 return -1;
19 }
20
21 void main()
22 {
23 int a[5] = {3,4,5,6,7};
24 printf("%d\n",bi_search(4,a,5));
25 }