Ruby CMath cbrt() Method with example
Last Updated :
07 Jan, 2020
cbrt method is a Math class method in Ruby which is used to calculate the cube root of the given value.
Syntax: Math.cbrt(z)
Parameter: Here, z is the value whose cube root is to be calculated.
Returns: This method returns the cube root of the given number.
Below programs illustrate the use of above-discussed method:
Example 1:
require 'cmath'
a = 27
b = 5 . 45
puts "Cube root value of a : #{CMath.cbrt(a)}\n\n"
puts "cube root value of b : #{CMath.cbrt(b)}\n\n"
|
Output:
Cube root value of a : 3.0
cube root value of b : 1.7598088635408027
Example 2:
require 'cmath'
a = 78
b = 729
puts "Cube root value of a : #{CMath.cbrt(a)}\n\n"
puts "cube root value of b : #{CMath.cbrt(b)}\n\n"
|
Output:
Cube root value of a : 4.272658681697917
cube root value of b : 8.999999999999998
Share your thoughts in the comments
Please Login to comment...