0% found this document useful (0 votes)
18 views2 pages

Radius of The Circle Program

Jjjj

Uploaded by

lakshmibhai1122
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views2 pages

Radius of The Circle Program

Jjjj

Uploaded by

lakshmibhai1122
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

2.

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

Aim: write a ruby program which accept the radius of a circle from the user and compute the parameter
and area

Procedure:

1.radius = gets.to_f

• The gets method is used to capture the user's input from the console.
• .to_f converts the captured input (which is initially a string) into a floating-point
number (decimal) suitable for calculations.
• This line assigns the user's input, converted to a float, to the variable radius.

2. PI = Math::PI

• This line defines a variable named PI and assigns the value of Math::PI to it.
• Math::PI is a built-in constant in the Ruby Math library that represents the
mathematical constant pi (approximately 3.14159...). Using this constant ensures
a more precise value for pi compared to hardcoding a specific number.

3. perimeter = 2 * PI * radius

• This line calculates the perimeter (circumference) of the circle.


• The formula for the circumference of a circle is 2 * pi * radius.
• We use the previously defined PI and the user-provided radius to calculate the
perimeter and store the result in the perimeter variable.
4.flow chart

Program:

radius = 5.0

perimeter = 0.0

area = 0.0

print "Input the radius of the circle: "

radius = gets.to_f

perimeter = 2 * 3.141592653 * radius

area = 3.141592653 * radius * radius

puts "The perimeter is #{perimeter}."

puts "The area is #{area}."

Output:
Input the radius of the circle : The perimeter is 31.41592653.

The area is 78.539816325

You might also like