Q:

Ruby program to calculate the area of the rhombus

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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 diagonal1diagonal2, area initialized with 0. Then we read values diagonal1diagonal2 from the user. After that, we calculated the area of the rhombus and printed the result.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now