#include
#include
using namespace std;
int main()
{
int arr[]={20,30,40,40,40,40,50,100,1100};
int n=sizeof(arr)/sizeof(int);
int key;
cin>>key;
bool present=binary_search(arr,arr+n,key);
if(present)
{
cout<<“present”<<endl;
}
else
{
cout<<“absent”<<endl;
}
auto lb=lower_bound(arr,arr+n,key);
if((lb-arr)==n)
{
cout<<“not present”<<endl;
}
else
{
cout<<(lb-arr)<<endl;
}
return 0;
}
sir this code working properly but when i am invin key as 12 it is showing 0 and if i am giving 444444 then is is giving me element is not present…
i want to say that this code is giving different answer for small number like 12,13 and giving right answer for big numbers like 122222or 4444, why so sir.