#include<stdio.h>
#include<stdlib.h>
int BinarySearch(int arr[],int size,int to_find) {
int left = 0;
int right = size - 1;
while (left <= right) {
int mid = (left + right) / 2;
if (to_find < arr[mid]) {
right = mid - 1;
}
else if (to_find > arr[mid]) {
left = mid + 1;
} else {
return mid;
}
}
return -1;
}
int main() {
int arr[4] = { 2,5,7,9 };
int result = BinarySearch(arr, 4, 2);
printf("result = %d\n", result);
system("pause");
return 0;
}