Find a Circle Radius from Its Area
Problem statement
Given the area of a circle, return its radius. For this exercise, the input is the area and the formula is radius = sqrt(area / PI), with PI = 3.141592653589793. An area of 0 has radius 0. Return a number; do not round it to a fixed number of decimal places.
Keep PI in shared constant storage and use it in the calculation. In C++, declare it as a function-local static const double. The portable references use a Java static field, Python class attribute, Go package constant or JavaScript static class field. The numeric judge checks the returned radius; it does not grade C syntax or prove a declaration's storage duration from the output.
Function
radiusFromArea(area: long) → doubleExamples
Example 1
area = 4return = 1.1283791670955126Dividing area 4 by PI gives about 1.273239544735163. Its square root is about 1.128379167095513, so that is the radius.
Example 2
area = 0return = 0.0An area of 0 gives sqrt(0 / PI) = 0. The radius is 0.
Constraints
0 <= area <= 1000000000000.- area is an integer. The input uses a signed 64-bit integer type; the result uses double precision.
- Use
PI = 3.141592653589793. - The judge accepts a result when its absolute error is at most
1e-9 * max(1, abs(expected)).