find the surface area of a rectangular prism in ruby

To find the surface area of a rectangular prism in Ruby, you need to use the following formula:

main.rb
surface_area = 2 * (length * width + length * height + width * height)
71 chars
2 lines

Here's a function that takes the length, width, and height of a rectangular prism as arguments and returns the surface area:

main.rb
def surface_area_rectangular_prism(length, width, height)
  surface_area = 2 * (length * width + length * height + width * height)
  return surface_area
end
157 chars
5 lines

You can call this function with your own length, width, and height values to find the surface area of any rectangular prism. Here's an example:

main.rb
length = 5
width = 3
height = 2

surface_area = surface_area_rectangular_prism(length, width, height)

puts "The surface area of a rectangular prism with length #{length}, width #{width}, and height #{height} is #{surface_area}."
230 chars
8 lines

gistlibby LogSnag