Given a number N, the task is to find the square root of N without using sqrt() function.
Input: N = 25
Input: N = 3
Input: N = 2.5
- Start iterating from i = 1. If i * i = n, then print i as n is a perfect square whose square root is i.
- Else find the smallest i for which i * i is strictly greater than n.
- Now we know square root of n lies in the interval i – 1 and i and we can use Binary Search algorithm to find the square root.
- Find mid of i – 1 and i and compare mid * mid with n, with precision upto 5 decimal places.
- If mid * mid = n then return mid.
- If mid * mid < n then recur for the second half.
- If mid * mid > n then recur for the first half.
Below is the implementation of the above approach:
- Check if a number is perfect square without finding square root
- Square root of a number using log
- Find square root of number upto given precision using binary search
- Fast method to calculate inverse square root of a floating point number in IEEE 754 format
- Square root of an integer
- Program to calculate Root Mean Square
- Babylonian method for square root
- Fast inverse square root
- Find Square Root under Modulo p | Set 1 (When p is in form of 4*i + 3)
- Find Square Root under Modulo p | Set 2 (Shanks Tonelli algorithm)
- Euler's criterion (Check if square root under modulo p exists)
- N-th root of a number
- Smallest root of the equation x^2 + s(x)*x - n = 0, where s(x) is the sum of digits of root x.
- Find cubic root of a number
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.