find the surface area of a sphere in ruby

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.rb
radius = 5
surface_area = 4 * Math::PI * radius**2

puts "The surface area of the sphere is: #{surface_area}"
110 chars
5 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.rb
The surface area of the sphere is: 314.1592653589793
53 chars
2 lines

related categories

gistlibby LogSnag