To find the surface area of a sphere in Ruby, we can use the formula:
surface_area = 4 * Math::PI * radius**2
where radius
is the radius of the sphere.
Here is the code to calculate the surface area of a sphere in Ruby:
main.rb110 chars5 lines
In this example, the radius of the sphere is set to 5
. We then use the formula to calculate the surface area, which is printed to the console using puts
. The output will be:
main.rb53 chars2 lines
gistlibby LogSnag