How to calculate the area of a pentagon in Ruby

2 Answers

0 votes
def pentagon_area(side, apothem)
  5.0 * (side * apothem) / 2.0
end

side = 5.0
apothem = 3.0

area = pentagon_area(side, apothem)

puts "Area = #{format('%.2f', area)}"



=begin
run:

Area = 37.50

=end

 



answered 4 hours ago by avibootz
0 votes
def area_regular_pentagon(side)
  (1.0 / 4.0) * Math.sqrt(5 * (5 + 2 * Math.sqrt(5))) * (side ** 2)
end

puts area_regular_pentagon(7)


=begin
run:

84.30339262885938

=end

 



answered 3 hours ago by avibootz
...