ADVERTISEMENT
ADVERTISEMENT

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 »


ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.