write a binary search algorithm to look for the presence of a search key in a single dimensional array of 10 elements. prompt the user to input 10 elements and the search key. display meaningful messages after the search operation.
#include<iostream.h>
#include<conio.h>
void main()
{
int p[10];
int search_key;
cout<<"\n enter 10 elements:"<<"\t";
for(int i=0; i<10; i++)
{
cin>>p[i];
}
cout<<"\n elements sorted:";
for(i=0; i<10; i++)
{
cout<<p[i]<<"\t";
}
cout<<"\n enter the search_key:";
cin>>search_key;
int middle, first=0, last=9;
while(first<=last)
{
middle=(first+last)/2;
middle+1;
cin>>search_key;
for(int index=0; index<10; index++)
{
if (p[index] == search_key)
{
cout<<"\n"<<search_key<<"found at location"<<index;break;
}
}
if(index>9)
cout<<"\n"<<search_key <<"not found";
getch();
}
}
i want to know if my program code is correct for this question or there are mistakes?