ADVERTISEMENT
ADVERTISEMENT

Ruby program to calculate the area of the rhombus

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

Problem Solution:

In this program, we will read diagonal1, diagonal2 from the user and then we will calculate the area of the rhombus and print the result.

Program/Source Code:

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

# Ruby program to calculate the 
# area of rhombus

diagonal1=0.0
diagonal2=0.0
area=0.0

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

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


area = 0.5 * diagonal1 * diagonal2;

print "Area of rhombus is: ",area;

Output:

Enter diagonal1: 2.3
Enter diagonal2: 1.2
Area of rhombus is: 1.38

Explanation:

In the above program, we created three variables diagonal1, diagonal2, area initialized with 0. Then we read values diagonal1, diagonal2 from the user. After that, we calculated the area of the rhombus 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.