find the surface area of a triangular prism in ruby

To find the surface area of a triangular prism in Ruby, you'll need to calculate the area of each face and add them together. The formula for surface area of a triangular prism is:

SA = 2 * base_area + lateral_area

Where base_area is the area of the triangular base, and lateral_area is the area of the three rectangular faces.

Here is a Ruby function that takes in the base length, height, and prism height as arguments and returns the surface area:

main.rb
def surface_area_of_triangular_prism(base_length, height, prism_height)
  base_area = (0.5 * base_length) * height
  lateral_area = base_length * prism_height
  total_area = 2 * base_area + 3 * lateral_area
  return total_area
end
231 chars
7 lines

To use this function, simply call surface_area_of_triangular_prism and provide the necessary arguments. For example, to find the surface area of a triangular prism with a base length of 4, height of 3, and prism height of 5:

main.rb
result = surface_area_of_triangular_prism(4, 3, 5)
puts result
# Output: 62.0
78 chars
4 lines

Therefore, the surface area of the given triangular prism is 62 square units.

gistlibby LogSnag