Q:

Ruby program to calculate the volume and area of Cone

belongs to collection: Ruby Basic Programs

0

In this program, we will read the height, radius of Cone from the user. Then we will calculate the volume and surface area of Cone 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 volume and area of Cone is given below. The given program is compiled and executed successfully.

# Ruby program to calculate the 
# volume, diagonal, and area of Cuboids

length=0.0;
height=0.0;
width =0.0;

diagonal=0.0;
volume=0.0;
area  =0.0;

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

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

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

diagonal = Math.sqrt((width * width)) + (length * length) + (height * height);
area     = 2.0 * (width * length) + (length * height) + (height * width);
volume   = width * length * height;

print "Diagonal of Cuboids  is: ",diagonal;    
print "\nVolume of Cuboids  is: ",volume;
print "\nArea of Cuboids  is: ",area;

Output:

Enter height: 15.6
Enter radius: 2.5
Volume of Cone is: 102.05
Area of Cone is: 143.64754724444262

Explanation:

In the above program, we created four variables heightradiusvolumearea that are initialized with 0.0. Then we read heightradius of Cone from the user and calculated the surface area and volume of Cone using the standard formula. After that, we printed the result.

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

total answers (1)

Ruby Basic Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Ruby program to calculate the volume and area of S... >>
<< Ruby program to calculate the volume, diagonal, an...