Ruby | Math sqrt() function
The sqrt() is an inbuilt function in Ruby returns the square root of a given value.
Syntax: Math.sqrt(value)
Parameters: The function accepts one mandatory parameter value whose square root is to be returned.
Return Value: It returns the square root of the value.
Example 1:
#Ruby program for sqrt() function #Assigning values val1 = 4 val2 = 9 val3 = 64 val4 = 100 #Prints the sqrt() value puts Math.sqrt(val1) puts Math.sqrt(val2) puts Math.sqrt(val3) puts Math.sqrt(val4) |
chevron_right
filter_none
Output:
2.0 3.0 8.0 10.0
Example 2:
#Ruby program for sqrt() function #Assigning values val1 = 40 val2 = 19 val3 = 164 val4 = 1200 #Prints the sqrt() value puts Math.sqrt(val1) puts Math.sqrt(val2) puts Math.sqrt(val3) puts Math.sqrt(val4) |
chevron_right
filter_none
Output:
6.324555320336759 4.358898943540674 12.806248474865697 34.64101615137755
Reference: https://devdocs.io/ruby~2.5/math#method-c-sqrt
Recommended Posts:
- Ruby | BigDecimal sqrt() function
- Ruby | Integer sqrt() function
- Ruby | Math erf() function
- Ruby | Math exp() function
- Ruby | Math sin() function
- Ruby | Math tan() function
- Ruby | Math log() function
- Ruby | Math cos() function
- Ruby | Math atanh() function
- Ruby | Math cbrt() function
- Ruby | Math sinh() function
- Ruby | Math tanh() function
- Ruby | Math ldexp() function
- Ruby | Math cosh() function
- Ruby | Math hypot() function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.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.



