#include <stdio.h>
int main() {
int data[9] = {1, 2, 4, 4, 4, 6, 7, 8, 10};
int num = 4;
int low,high,mid;
low = 0;
high = sizeof(data)/sizeof(int) - 1;
while(low <= high){
mid = (low + high) / 2;
if(num == data[mid]){
if(data[mid] == data[mid+1]){
printf("%d ",mid);
return 0;
}
else{
high = mid - 1;
}
}
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: