Radius of The Circle Program
Radius of The Circle Program
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
Program:
radius = 5.0
perimeter = 0.0
area = 0.0
radius = gets.to_f
Output:
Input the radius of the circle : The perimeter is 31.41592653.