Ruby program to calculate the volume of Cube

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

Problem Solution:

In this program, we will read the side of Cube from the user. Then we will calculate the volume of the Cube and print the result.

Program/Source Code:

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

# Ruby program to calculate 
# the volume of Cube

side=0.0;
volume=0.0;

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

volume = side * side * side;

print "Volume of Cube is: ",volume;

Output:

Enter side: 2.43
Volume of Cube is: 14.348907000000002

Explanation:

In the above program, we created two variables side and volume, that are initialized with 0.0. Then we read the side of Cube from the user and calculated the volume of Cube using the standard formula. After that, we printed the result.

Ruby Basic Programs »




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.