Write a program to implement binary search

Write a program to implement binary search

#include <iostream>

using namespace std;

cout<<"element found at:"<<check+3;

}

elseint binary Search (int arr [], int date, int Shert ,int end)

{

int index=-1

int mid = (stert + end)/2;

while (start <= end)

{

     if(arr [mid] <data)

{

       Start = mid + 1;

}

 else if (arr [mid] = = data)

{

     index = mid+1;

}

    else if (arr [mid] ==data)

{

      index=mid:

       return index;

}

else if (are[mid]>data

{

end=mid-1;

}

mid=(start+end)/2;

}

return -1;

}

int main()

{

int arr[100];

int n, data, i;

 Cout <<"Enter the no. of elements of array"<< endl;

Cin>>n;

cout <<"Enter the element of an array:"endl;

 for (i=0; i<n; i++) 

cin >> arr [i];

Cout <<"Enter the date to search :";

(arr,data,start,end)

if(check!==-1)

}

{

cout<<"element not found";

}

Comments

Popular posts from this blog

BPSC 66th Exam Interview 2022: बीपीएससी 66वीं परीक्षा के साक्षात्कार 18 जुलाई को, कॉल लेटर जारी

पिता को नौकरी दिलाने में पुत्र ने अपना करियर दांव पर लगायाः होमगार्ड बहाली में बाप के बदले दौर लगा रहा बेटा गिरफ्तार