Binary Search Recursive
Binary Search Recursive
#include <stdio.h>
if (target == nums[mid]) {
return mid;
}
else {
return binarySearch(nums, mid + 1, high, target);
}
}
int main( )
{
int nums[] = { 2, 5, 6, 8, 9, 10 };
int target = 5;
int n = sizeof(nums)/sizeof(nums[0]);
int low = 0, high = n - 1;
int index = binarySearch(nums, low, high, target);
if (index != -1) {
printf("Element found at index %d", index);
}
else {
printf("Element not found in the array");
}
return 0;
}