Given the radius of a circle, calculate its circumference and area.
The circumference of a circle with radius r is given by 2 × π × r or two times pi times the radius.
The area of a circle with radius r is given by π × r ² or pi times the square of the radius.
The number π, or pi, is a mathematical constant with an irrational value of 3.141 592 653 …
Each line of input contains a decimal value r indicating the radius.
0 < r < 10000.0
For each line of input, your program should produce two numbers, c and a indicating the circumference and area. They should be rounded to two decimal places.
Input is terminated by the end-of-file (EOF).
1
12
6.6
0.159
6.28 3.14
75.40 452.39
41.47 136.85
1.00 0.08
circumference
and area
To reach a full score your program should implement two functions
circumference
and area
.
Each should take a double-precision floating point number
and return a double-precision floating point number.
Please see the information for your programming language of choice:
double circumference(double r);
and double area(double r);
def circumference(r):
and def circumference(r):
circumference :: Double -> Double
and area :: Double -> Double
double circumference(double r);
and double area(double r);
public static double Circumference(double r)
and public static double Area(double r)
public static double circumference(double r)
and public static double area(double r)
in a public class Pi
function circumference(r)
, function area(r)
function circumference (r)
and function area (r)
def circumference(r)
and def area(r)
circumference
and area
The value of π (pi).
The value of π (pi) is a real number so the only way to represent it as a
floating point value is to use an approximation.
Although you can use a hardcoded value of 3.141592653589793
for π
it is better to use the one provided by your programming language of
choice:
try first: mult
Copyright © 2020-2021 Rudy Matela
This text is available under the CC BY-SA 4.0 license.
Originally available on cscx.org/pi