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<