Given an integer N and a tolerance level L, the task is to find the square root of that number using Newton’s Method.
Input: N = 16, L = 0.0001
42 = 16
Input: N = 327, L = 0.00001
Let N be any number then the square root of N can be given by the formula:
root = 0.5 * (X + (N / X)) where X is any guess which can be assumed to be N or 1.
- In the above formula, X is any assumed square root of N and root is the correct square root of N.
- Tolerance limit is the maximum difference between X and root allowed.
Approach: The following steps can be followed to compute the answer:
- Assign X to the N itself.
- Now, start a loop and keep calculating the root which will surely move towards the correct square root of N.
- Check for the difference between the assumed X and calculated root, if not yet inside tolerance then update root and continue.
- If the calculated root comes inside the tolerance allowed then break out of the loop.
- Print the root.
Below is the implementation of the above approach:
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Find cubic root of a number
- C program to find square root of a given number
- Find Cube root of a number using Log function
- Find Nth positive number whose digital root is X
- Program to find root of an equations using secant method
- Long Division Method to find Square root with Examples
- 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
- Nth root of a number using log
- N-th root of a number
- Find Square Root under Modulo p | Set 1 (When p is in form of 4*i + 3)
- Square root of a number using log
- Smallest root of the equation x^2 + s(x)*x - n = 0, where s(x) is the sum of digits of root x.
- Find Square Root under Modulo p | Set 2 (Shanks Tonelli algorithm)
- Square root of a number without using sqrt() function
- Primitive root of a prime number n modulo n
- Print a number containing K digits with digital root D
- Babylonian method for square root
- Floor value Kth root of a number using Recursive Binary Search
- Check if a number is perfect square without finding square root
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.