logo image

Ruby program to calculate trapezoid circumference

30


Following program shows you how to calculate trapezoid circumference. This program gets trapezoid bases and sides from user and calculates circumference and prints it using following formula Circumference = base1 + base2 + side1 +side2

 puts "Please enter base1 of trapezoid:"
 trapezoidBase1 = gets.to_f
 puts "Please enter base2 of trapezoid:"
 trapezoidBase2 = gets.to_f
 puts "Please enter side1 of trapezoid:"
 trapezoidSide1 = gets.to_f
 puts "Please enter side2 of trapezoid:"
 trapezoidSide2 = gets.to_f
 circumferenceOfTrapezoid = trapezoidBase1 + trapezoidBase2 + trapezoidSide1 + trapezoidSide2
 puts "Circumference of trapezoid is: #{circumferenceOfTrapezoid}"

Output:

Please enter base1 of trapezoid:
3
Please enter base2 of trapezoid:
4
Please enter side1 of trapezoid:
8
Please enter side2 of trapezoid:
10
Circumference of trapezoid is: 25.0