#include <stdio.h>

int binarysearch(int a[],int x,int low,int high){
    while(low<=high){
        int mid=low+(high-low)/2;
        
        if(a[mid]==x){
            printf("%d",mid);
        }
        if(a[mid]<x){
            low=mid+1;
        }
        else{
            high=mid-1;
        }
    }
}

int main() {
    int a[10];
    int n=8;
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    int x = 3;
    
    binarysearch(a,x,0,n-1);
}

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: