All challenges
Easy 0 solved 0% acceptance

Average of Three

Average three whole numbers.

Problem

Compute the average (arithmetic mean) of three integers. The result can have a fractional part.

Implement average_of_three(a, b, c).

Input

a: The first number. b: The second number. c: The third number.

Output

Return (a + b + c) / 3 as a decimal number.

Constraints

-1,000,000 ≤ a, b, c ≤ 1,000,000

Examples

Example 1
Input:
a = 2
b = 4
c = 9

Expected output:
expected = 5.0
Input:
long long a = 2;
long long b = 4;
long long c = 9;

Expected output:
double expected = 5.0;
Input:
long a = 2;
long b = 4;
long c = 9;

Expected output:
double expected = 5.0;

Explanation

2 + 4 + 9 = 15 and 15 / 3 = 5.

Example 2
Input:
a = 1
b = 2
c = 2

Expected output:
expected = 1.666667
Input:
long long a = 1;
long long b = 2;
long long c = 2;

Expected output:
double expected = 1.666667;
Input:
long a = 1;
long b = 2;
long c = 2;

Expected output:
double expected = 1.666667;

Explanation

1 + 2 + 2 = 5 and 5 / 3 ≈ 1.666667. Divide as decimals, not whole numbers.

References

This challenge is adapted for CodeUtility. Follow the statement and constraints above.

Learn from others

Community solutions

No published solutions yet. Solve this challenge to share the first one.