find the area of a triangle in ruby

To find the area of a triangle in Ruby, you can use the formula:

area = 0.5 * base * height

where base is the length of the base of the triangle, and height is the height of the triangle.

Here's how you can implement this formula in Ruby:

main.rb
def triangle_area(base, height)
  area = 0.5 * base * height
  return area
end
79 chars
5 lines

You can then call this method with the base and height of the triangle as arguments, like this:

main.rb
area = triangle_area(7, 4)
puts "The area of the triangle is #{area}"
70 chars
3 lines

This will output: The area of the triangle is 14.0

gistlibby LogSnag