Ruby CMath sqrt() Method with example
sqrt method is a Math class method in Ruby which is used to calculate the square root of the given value.
Syntax: Math.sqrt(z)
Parameter: Here, z is the value whose square root is to be calculated.
Returns: This method returns the square root of the given number.
Below programs illustrate the use of above-discussed method:
Example 1:
# Ruby code for sqrt() method require 'cmath' # Initialize values a = 9b = 78.15 # Printing result puts "Square root value of a : #{CMath.sqrt(a)}\n\n" puts "Square root value of b : #{CMath.sqrt(b)}\n\n" |
chevron_right
filter_none
Output:
Square root value of a : 3.0 Square root value of b : 8.84024886527523
Example 2:
# Ruby code for sqrt() method require 'cmath' # Initializing value a = 7841b = 1234 # Printing result puts "Sqrt root value of a : #{CMath.sqrt(a)}\n\n" puts "Sqrt root value of b : #{CMath.sqrt(b)}\n\n" |
chevron_right
filter_none
Output:
Sqrt root value of a : 88.54942122905152 Sqrt root value of b : 35.12833614050059
Recommended Posts:
- Private Classes in Ruby
- Ruby | Matrix cofactor() function
- Ruby Integer odd? function with example
- Ruby Integer div() function with example
- Ruby | Symbol to_s function
- Ruby | Set replace() function
- Ruby | Set reset() function
- Ruby For Beginners
- Ruby | Array Concatenation using (+) function
- Ruby | at() function
- Ruby Float to_r() method with example
- Ruby | Keywords
- Ruby | Exception Class and its Methods
- Ruby | String inspect Method
- Ruby | Numeric imaginary() 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.



