From 6cd32d216bfff6327e51b84f77bd4f851b346e3e Mon Sep 17 00:00:00 2001 From: Hazel Mahajan <43532476+hazel11182@users.noreply.github.com> Date: Fri, 2 Apr 2021 23:35:47 +0530 Subject: [PATCH] Create-sqrt-monotonic-binary-search.cpp (#114) * Create sqrt_monotonic_binary_search.cpp * Rename sqrt_monotonic_binary_search.cpp to sqrt-monotonic-binary-search.cpp * update string index readme add sqrt-monotonic-binary-search.cpp under c-or-cpp Co-authored-by: Arsenic <54987647+Arsenic-ATG@users.noreply.github.com> Co-authored-by: Ming Tsai <37890026+ming-tsai@users.noreply.github.com> --- searching/README.md | 3 +- .../c-or-cpp/sqrt-monotonic-binary-search.cpp | 39 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 searching/c-or-cpp/sqrt-monotonic-binary-search.cpp diff --git a/searching/README.md b/searching/README.md index 271062a7..d1b2a252 100644 --- a/searching/README.md +++ b/searching/README.md @@ -5,7 +5,8 @@ 1. [Linear Search](c-or-cpp/linear-search.cpp) 2. [Binary Search](c-or-cpp/binary-search.cpp) 3. [Jump Search](c-or-cpp/jump-search.cpp) -4. [Interpolation Search](c-or-cpp/interpolation-search.cpp) +4. [finding squareroot using binary search](c-or-cpp/sqrt-monotonic-binary-search.cpp) +5. [Interpolation Search](c-or-cpp/interpolation-search.cpp) ### Python diff --git a/searching/c-or-cpp/sqrt-monotonic-binary-search.cpp b/searching/c-or-cpp/sqrt-monotonic-binary-search.cpp new file mode 100644 index 00000000..3cd6e517 --- /dev/null +++ b/searching/c-or-cpp/sqrt-monotonic-binary-search.cpp @@ -0,0 +1,39 @@ +#include + using namespace std; + float square_root(int a,int p){ + int s=0; + int e=a; + float ans=-1; + int mid; + while(s<=e){ + mid=(s+e)/2; + if (mid*mid==a) + return mid; + else if(mid*mid>n; + + cout<