๐Ÿ“œ
B.TECH III YEAR โ€ข II SEMESTER โ€ข R22

Scripting Languages - Lab Manual

Scripting Languages Laboratory โ€ข Program 2 Solution

๐Ÿ“˜ R22 Regulation ๐ŸŽ“ III Year ๐Ÿ“š II Semester ๐Ÿ“œ Scripting Languages ๐Ÿ’Ž Ruby โ€ข TCL โ€ข Perl ๐Ÿงช Lab Program
Aim of Program 2

Write a Ruby script which accept the radius of a circle from the user and compute the perimeter and area.

โ† All Programs
Solution

Aim:

☛   Write a Ruby program which accept the radius of a circle from the user and compute the perimeter and area.

Solution :

PROGRAM: (perimeter_area.rb)

 
print "Enter the radius of the circle: "
radius = gets.to_f

perimeter = 2 * Math::PI * radius
area = Math::PI * radius**2

puts "Perimeter (Circumference): #{perimeter.round(4)}"
puts "Area: #{area.round(4)}"


OUTPUT:

 
Enter the radius of the circle: 5.0
Perimeter : 31.4
Area: 78.5



โ† Back to Scripting Languages Lab Programs ๐Ÿ“š All Lab Manuals