ADVERTISEMENT
ADVERTISEMENT

Ruby program to calculate the area of Parallelogram

Ruby Example: Write a program to calculate the area of Parallelogram.
Submitted by Nidhi, on November 29, 2021

Problem Solution:

In this program, we will read the base and altitude from the user. Then we will calculate the area of the Parallelogram and print the result.

Program/Source Code:

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

# Ruby program to calculate the 
# area of Parallelogram

base=0.0;
altitude=0.0;
area=0.0;

print "Enter base: ";
base = gets.chomp.to_f;  

print "Enter altitude: ";
altitude = gets.chomp.to_f;  

area = base * altitude;

print "Area of Parallelogram is: ",area;

Output:

Enter base: 3.13
Enter altitude: 4.6
Area of Parallelogram is: 14.397999999999998

Explanation:

In the above program, we created three variables base, altitude, area, that are initialized with 0.0. Then we read base, altitude from the user and calculated the area of Parallelogram using the standard formula. After that, we 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.