For a given number find the square root using log function. Number may be int, float or double.
Input : n = 9 Output : 3 Input : n = 2.93 Output : 1.711724
We can find square root of a number using sqrt() method.
We can also find square root using log2() library function:
Input :7 Output:2.645751
How does above program work?
let d be our answer for input number n then n(1/2) = d apply log2 on both sides log2(n(1/2)) = log2(d) log2(d) = 1/2 * log2(n) d = 2(1/2 * log2(n)) d = pow(2, 0.5*log2(n))
This article is contributed by Tumma Umamaheswararao from Jntuh College of Engineering . 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 write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Find square root of number upto given precision using binary search
- Break the number into three parts
- Implement *, - and / operations using only + arithmetic operator
- Perfect cubes in a range
- Maximum value of an integer for which factorial can be calculated on a machine
- Find the closest and smaller tidy number
- Find ways an Integer can be expressed as sum of n-th power of unique natural numbers
- Check if a large number is divisible by 11 or not
- N-th root of a number
- Bakhshali Approximation for computing square roots
- Find Last Digit of a^b for Large Numbers
- Find Square Root under Modulo p | Set 2 (Shanks Tonelli algorithm)
- Square root of an integer
- Fast method to calculate inverse square root of a floating point number in IEEE 754 format
- Babylonian method for square root
Improved By : Sanjit_Prasad