Square root of a number by Repeated Subtraction method | C ++ implementation of the above approach ; Function to return the square root of the given number ; Subtract n - th odd number ; Return the result ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int SquareRoot ( int num ) { int count = 0 ; for ( int n = 1 ; n <= num ; n += 2 ) { num = num - n ; count += 1 ; if ( num == 0 ) break ; } return count ; } int main ( ) { int N = 81 ; cout << SquareRoot ( N ) ; }