The given an integer x, find square root of it. If x is not a perfect square, then it returns floor(√x).
To find a floor of square root to try all numbers starting from 1. For every tried number i, if i*i is smaller than x, then increment i. We stop when i*i becomes more than or equal to x.
See the following running code to find square root:-
//Time Complexity O(squareroot N)
public static int getSqt(int num) {
if(num ==0 || num==1)
return 1;
int i=1;
while(i*i <= num) {
i++;
}
return i-1;
}