Square root of an integer | A C ++ program to find floor ( sqrt ( x ) ; Returns floor of square root of x ; Base cases ; Starting from 1 , try all numbers until i * i is greater than or equal to x . ; Driver program
#include <bits/stdc++.h> NEW_LINE using namespace std ; int floorSqrt ( int x ) { if ( x == 0 x == 1 ) return x ; int i = 1 , result = 1 ; while ( result <= x ) { i ++ ; result = i * i ; } return i - 1 ; } int main ( ) { int x = 11 ; cout << floorSqrt ( x ) << endl ; return 0 ; }