index | submit | rank | book

pi – Circumference and Area

Given the radius of a circle, calculate its circumference and area.

diagram showing the circumference and area of a circle

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 …

Input and Output

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).

Example input

1
12
6.6
0.159

Example output

6.28 3.14
75.40 452.39
41.47 136.85
1.00 0.08

Functions 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:

Scoring

Hints

  1. 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:

    • in C, use M_PI from math.h;
    • in Python, use pi from the math module (a.k.a.: math.pi);
    • in Haskell use pi from the Prelude.

try first: mult

try next: oddeven order

index | submit | rank | book

Copyright © 2020-2023 Rudy Matela
All rights reserved