#include <stdio.h>
#include <stdlib.h>
int ts(int* array, int start, int end, int search) {
printf("Searching from %d to %d for %d\n",start,end, search);
int m = (start+end)/2; /* integer division */
if (array[m] == search) {
return(m);
}
/* if the middle is less than what we need, we look above */
else if (array[m] < search) {
return(ts(array,m,end,search));
}
/* if the middle is more than what we need, we look below */
else {
return(ts(array,start,m,search));
}
}
int main(int argc, char* argv[]) {
int arraysize = 10;
int search = 4;
int mynumbers[] = {0,1,2,3,4,5,6,7,8,9};
printf("Result: %d\n",ts(mynumbers,0,arraysize,search));
return(0);
}