From a639eddb58ecf019fd3b24f8e72d450ac62d4e4d Mon Sep 17 00:00:00 2001 From: Fatemask Date: Sat, 16 Oct 2021 10:45:19 +0530 Subject: [PATCH] binary search algo --- binary_Search.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 binary_Search.cpp diff --git a/binary_Search.cpp b/binary_Search.cpp new file mode 100644 index 0000000..f3d5478 --- /dev/null +++ b/binary_Search.cpp @@ -0,0 +1,42 @@ +#include +using namespace std; + +int main() +{ + int count, i, arr[30], num, first, last, middle; + cout<<"how many elements would you like to enter?:"; + cin>>count; + + for (i=0; i>arr[i]; + } + cout<<"Enter the number that you want to search:"; + cin>>num; + first = 0; + last = count-1; + middle = (first+last)/2; + while (first <= last) + { + if(arr[middle] < num) + { + first = middle + 1; + + } + else if(arr[middle] == num) + { + cout< last) + { + cout<