# Ruby program to calculate the volume and area of Cone

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

Problem Solution:

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.

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
Volume of Cone is: 102.05
Area of Cone is: 143.64754724444262
```

Explanation:

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

Preparation

What's New

Top Interview Coding Problems/Challenges!