Home »
Ruby Tutorial »
Ruby Programs
Ruby program to calculate the area of the rhombus
Last Updated : December 15, 2025
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