#include <stdio.h>
#include <string.h>
int main() {
char *data[] = {"apple", "banana", "cherry", "grape", "orange", "strawberry"};
char *num = "cherry";
int low = 0, high = 5, mid;
while(low <= high){
mid = (low + high) / 2;
int cmp = strcmp(num, data[mid]);
if(cmp == 0){
printf("%d ", mid);
return 0;
}
else if(cmp > 0){
low = mid + 1;
}
else{
high = mid - 1;
}
}
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: