Program to search element using Binary Search.

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