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.
Program/Source Code:
The source code to calculate the area of Trapezium is given below. The given program is compiled and executed successfully.
Output:
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.
need an explanation for this answer? contact us directly to get an explanation for this answer