Ruby program to calculate triangle area

Views: 664   

Following program shows you how to calculate triangle area.
This program gets triangle base and height from user and calculates area and prints it using following formula
Area = base X height / 2

 puts "Enter the base of triangle:"
 triangleBase = gets.to_f
 puts "Enter the height of triangle:"
 triangleHeight = gets.to_f
 areaOfTriangle = (triangleBase * triangleHeight) / 2
 puts "Area of triangle is: #{areaOfTriangle}"
### Output:

Enter the base of triangle:
Enter the height of triangle:
Area of triangle is: 3.0

On By