29. Average to Two Decimal Places
Difficulty: easy · Math
Problem
Given `n` integers, print their average **rounded to exactly 2 decimal places**. Round halves away from zero (for example `2.125` becomes `2.13` and `-2.125` becomes `-2.13`). Always print two digits after the decimal point, and print `0.00` rather than `-0.00`.
Input
- Line 1: the integer `n`. - Line 2: `n` space-separated integers.
Output
Print the average with exactly two digits after the decimal point.
Example 1
Input: 3 1 2 4 Output: 2.33
Explanation: The sum is 7 and 7/3 = 2.3333..., which rounds to 2.33.
Example 2
Input: 8 1 1 1 1 1 1 1 10 Output: 2.13
Explanation: 17/8 = 2.125 exactly; the half rounds away from zero, giving 2.13.
Example 3
Input: 2 -1 0 Output: -0.50
Explanation: -1/2 = -0.5, printed as -0.50.
Constraints
- 1 <= n <= 10^5 - -10^9 <= each value <= 10^9
Solutions are judged against 3 sample and 10 hidden tests. Sign in to solve it · All problems