#include <stdio.h>
int main() {
int data[6] = {2, 4, 6, 8, 10, 12};
int num = 5;
int low,high,mid;
low = 0;
high = sizeof(data)/sizeof(int) - 1;
while(low <= high){
mid = (low + high) / 2;
if(num > data[mid-1] && num < data[mid+1]){
printf("%d ",mid);
return 0;
}
else if(num > data[mid]){
low = mid + 1;
}
else if(num < data[mid]){
high = mid - 1;
}
}
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: