#include using namespace std; int binarySearch(int[], int, int, int); int main () { int arr[10] = {16, 19, 20, 23, 45, 56, 78, 90, 96, 100}; int item, location=-1; cout<<"Enter the item which you want to search: "; cin>>item; location = binarySearch(arr, 0, 9, item); if(location != -1) { cout<<"Item found at location:"<= beg) { mid = (beg + end)/2; if(a[mid] == item) { return mid+1; } else if(a[mid] < item) { return binarySearch(a,mid+1,end,item); } else { return binarySearch(a,beg,mid-1,item); } } return -1; } Q: edit the code that shows after how many number of iteration searched value is found
#include<iostream>
using namespace std;
int binarySearch(int[], int, int, int);
int main ()
{
int arr[10] = {16, 19, 20, 23, 45, 56, 78, 90, 96, 100};
int item, location=-1;
cout<<"Enter the item which you want to search: ";
cin>>item;
location = binarySearch(arr, 0, 9, item);
if(location != -1)
{
cout<<"Item found at location:"<<location;
}
else
{
cout<<"Item not found";
}
return 0;
}
int binarySearch(int a[], int beg, int end, int item)
{
int mid;
if(end >= beg)
{
mid = (beg + end)/2;
if(a[mid] == item)
{
return mid+1;
}
else if(a[mid] < item)
{
return binarySearch(a,mid+1,end,item);
}
else
{
return binarySearch(a,beg,mid-1,item);
}
}
return -1;
}
Q: edit the code that shows after how many number of iteration searched value is found
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 3 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![C++ for Engineers and Scientists](https://www.bartleby.com/isbn_cover_images/9781133187844/9781133187844_smallCoverImage.gif)
![EBK JAVA PROGRAMMING](https://www.bartleby.com/isbn_cover_images/9781337671385/9781337671385_smallCoverImage.jpg)
![C++ for Engineers and Scientists](https://www.bartleby.com/isbn_cover_images/9781133187844/9781133187844_smallCoverImage.gif)
![EBK JAVA PROGRAMMING](https://www.bartleby.com/isbn_cover_images/9781337671385/9781337671385_smallCoverImage.jpg)