Sir i am not able to find the element in an array using binary search please help me! my code is below

#include
using namespace std;
int binary_search( int arr[],int size,int key){
int mid,start,end;
start=0;
end=size-1;
while(start>=end){
mid=(start+end)/2;
if(arr[mid]==key)
{
return mid;
}
else if (arr[mid]<key)
{
start=mid+1;
}
else
{
end=mid-1;
}
}
return -1;
}

int main(){
int key;
int arr[5]={2,4,6,8,10};
cout<<“enter the value you want to search in an array”<<endl;
cin>>key;
cout<<binary_search( arr,5,key);
return 0;

}

hello @anshulgurawalia

pls save ur code here->https://ide.codingblocks.com/
and share the link with me

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.