Q:

Ruby program to calculate the area of Trapezium

belongs to collection: Ruby Basic Programs

0

In this program, we will read base1base2, and height from the user and then we will calculate the area of Trapezium and print the result.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program/Source Code:

The source code to calculate the area of Trapezium is given below. The given program is compiled and executed successfully.

# Ruby program to calculate the 
# area of Trapezium

base1=0
base2=0
height=0
area=0

print "Enter base1: ";
base1 = gets.chomp.to_i;  

print "Enter base2: ";
base2 = gets.chomp.to_i;  

print "Enter height: ";
height = gets.chomp.to_i;

area = 0.5 * (base1 + base2) * height;
    
print "Area of Trapezium is: ",area;

Output:

Enter base1: 3
Enter base2: 4
Enter height: 2
Area of Trapezium is: 7.0

Explanation:

In the above program, we created four variables base1base2height, area initialized with 0. Then we read values base1base2height from the user. After that, we calculated the area of the Trapezium and printed the result.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Ruby Basic Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Ruby program to calculate the area of the rhombus... >>
<< Ruby program to calculate the Lowest Common Multip...