logo image

Ruby program to calculate triangle circumference

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

 puts "Enter the side1 of triangle:"
 triangleSide1 = gets.to_f
 puts "Enter the side2 of triangle:"
 triangleSide2 = gets.to_f
 puts "Enter the side3 of triangle:"
 triangleSide3 = gets.to_f
 circumferenceOfTriangle = triangleSide1 + triangleSide2 + triangleSide3
 puts "Circumference of triangle is: #{circumferenceOfTriangle}"


Enter the side1 of triangle:
Enter the side2 of triangle:
Enter the side3 of triangle:
Circumference of triangle is: 60.0