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
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.
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.
How to approach it
Try on your own first, then open one hint at a time.
Hint 1
Add the three values first, then spread the total across three equal parts.
Hint 2
Use ordinary arithmetic division so non-integer results are preserved.
Hint 3
Watch for languages that do integer division by default, since that would drop the fractional part.
Expected complexity
O(1) time, O(1) extra space
References
This challenge is adapted for CodeUtility. Follow the statement and constraints above.