oneby7

Foundations Data types

585. Average of Three Numbers

Easy

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

Output: 6.666666666666667

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

Output: -2.3333333333333335

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

Output: 1000000000

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

a = 1, b = 2, c = 2

Constraints

  • -109 ≤ a, b, c ≤ 109

Clarifying questions

What you would ask an interviewer before writing any code.

Hints

Interview follow-ups

Runs in your browser
Code
Runs in your browser for now · some things may not work as expectedLn 1, Col 1

Article

Send feedback

Thank you for helping. We read every report and fix what is wrong.

How do you feel about oneby7?

Sign in to oneby7

Keep your progress, your streak and your code, on any device.

New here? This creates your account too.