Floor square root without using sqrt ( ) function : Recursive | C ++ implementation to find the square root of the number N without using sqrt ( ) function ; Function to find the square root of the number N using BS ; If the range is still valid ; Find the mid - value of the range ; Base Case ; Condition to check if the left search space is useless ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int sqrtSearch ( int low , int high , int N ) { if ( low <= high ) { int mid = ( low + high ) / 2 ; if ( ( mid * mid <= N ) && ( ( mid + 1 ) * ( mid + 1 ) > N ) ) { return mid ; } else if ( mid * mid < N ) { return sqrtSearch ( mid + 1 , high , N ) ; } else { return sqrtSearch ( low , mid - 1 , N ) ; } } return low ; } int main ( ) { int N = 25 ; cout << sqrtSearch ( 0 , N , N ) << endl ; return 0 ; }