Foundations Data types
585. Average of Three Numbers
You are given three integers a, b and c. Return their average as a decimal number (a double, or a
float in Python).
The average of three numbers is their sum divided by 3. It does not have to be a whole number: the average of 1, 2 and 4 is 7 / 3 = 2.333…, with the 3 repeating.
The answer is a floating-point number, and different correct ways of computing it can round differently in the last digits. So an answer counts as right when it is within 10−6 of the expected answer, or, for an expected answer larger than 1 in absolute value, within 10−6 times that answer.
Example 1
Input: a = 4, b = 7, c = 9
6.666666666666667Explanation: The sum is 4 + 7 + 9 = 20, and 20 / 3 is 6.666…, with the 6 repeating.
Example 2
Input: a = -5, b = -1, c = -1
-2.3333333333333335Explanation: The sum is −7, so the average is −7 / 3, about −2.333. It is negative, and it lies between −3 and −2.
Example 3
Input: a = 1000000000, b = 1000000000, c = 1000000000
1000000000Explanation: All three numbers are 109, so the average is 109 too. Their sum is 3 × 109.
Check your understanding
Work out the answer for this input before you write any code.
Constraints
-109 ≤ a, b, c ≤ 109
Clarifying questions
What you would ask an interviewer before writing any code.