Ruby program to calculate the area of Trapezium

Ruby Example: Write a program to calculate the area of Trapezium.
Submitted by Nidhi, on December 06, 2021

Problem Solution:

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

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 base1, base2, height, area initialized with 0. Then we read values base1, base2, height from the user. After that, we calculated the area of the Trapezium and printed the result.

Ruby Basic Programs »





Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.