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.
- Babylonian method for square root
- Square root of an integer
- Maximum value of an integer for which factorial can be calculated on a machine
- Find Last Digit of a^b for Large Numbers
- Bakhshali Approximation for computing square roots
- Number of Permutations such that no Three Terms forms Increasing Subsequence
- Check if the first and last digit of the smallest number forms a prime
- Print all substring of a number without any conversion
- Complement of a number with any base b
- Check if Decimal representation of an Octal number is divisible by 7