ADVERTISEMENT
ADVERTISEMENT

Ruby program to calculate the volume and area of the Cylinder

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

Problem Solution:

In this program, we will read the radius and height of the Cylinder from the user. Then we will calculate the volume and surface area of the Cylinder and print the result.

Program/Source Code:

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

# Ruby program to calculate the
# volume and area of Cylinder

radius=0.0;
height=0.0;
volume=0.0;
area  =0.0;

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

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

volume = 3.14 * radius * radius * height;
area   = 2.0 * 3.14 * radius * (radius + height);
    
print "Volume of Cylinder is: ",volume;
print "\nArea of Cylinder is: ",area;

Output:

Enter radius: 6
Enter height: 2.34
Volume of Cylinder is: 264.51359999999994
Area of Cylinder is: 314.2512

Explanation:

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

Ruby Basic Programs »


ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.