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:
- Floor square root without using sqrt() function : Recursive
- Find all Factors of Large Perfect Square Natural Number in O(sqrt(sqrt(N))
- 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
- Fast inverse square root
- Program to calculate Root Mean Square
- Babylonian method for square root
- Find Square Root under Modulo p | Set 1 (When p is in form of 4*i + 3)
- Long Division Method to find Square root with Examples
- Euler's criterion (Check if square root under modulo p exists)
- Find Square Root under Modulo p | Set 2 (Shanks Tonelli algorithm)
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.