Ruby CMath cbrt() Method with example

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby code for cbrt() method
require 'cmath'
  
# Initializing value
a = 27
b = 5.45
  
# Printing result  
puts "Cube root value of a : #{CMath.cbrt(a)}\n\n" 
puts "cube root value of b : #{CMath.cbrt(b)}\n\n"

chevron_right


Output:

Cube root value of a : 3.0

cube root value of b : 1.7598088635408027

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby code for cbrt() method
require 'cmath'
  
# Initializing values 
a = 78
b = 729
  
# Printing result  
puts "Cube root value of a : #{CMath.cbrt(a)}\n\n" 
puts "cube root value of b : #{CMath.cbrt(b)}\n\n"

chevron_right


Output:

Cube root value of a : 4.272658681697917

cube root value of b : 8.999999999999998


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.