I am executing program by using binary_search function for the array with element [1,5,6,4,8] .The code is working fine for all elements but showing wrong result for element 4.
code for refrence :-
#include
#include
using namespace std;
int main() {
int arr[] = {1,5,6,4,8};
int n = sizeof(arr)/sizeof(int);
int key;
cin>>key;
bool found = binary_search(arr,arr+n,key);
if(found)
{
cout<<"Element found";
}
else{
cout<<"Not found";
}
}