find the volume of a cone in ruby

To find the volume of a cone in Ruby, you can use the following formula:

main.rb
volume = (1.0/3) * Math::PI * radius**2 * height
49 chars
2 lines

Where radius is the radius of the base of the cone, height is the height of the cone, and Math::PI is the mathematical constant for pi.

Here's an example code block that computes the volume of a cone with a radius of 5 and a height of 10:

main.rb
radius = 5
height = 10
volume = (1.0/3) * Math::PI * radius**2 * height

puts "The volume of the cone is #{volume.round(2)}."
126 chars
6 lines

This code will output:

main.rb
The volume of the cone is 261.8.
33 chars
2 lines

related categories

gistlibby LogSnag