Условие
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.
Ограничения
-1,000,000 ≤ a, b, c ≤ 1,000,000
Примеры
Ввод:
a = 2
b = 4
c = 9
Ожидаемый вывод:
expected = 5.0
Ввод:
long long a = 2;
long long b = 4;
long long c = 9;
Ожидаемый вывод:
double expected = 5.0;
Ввод:
long a = 2;
long b = 4;
long c = 9;
Ожидаемый вывод:
double expected = 5.0;
Пояснение
2 + 4 + 9 = 15 and 15 / 3 = 5.
Ввод:
a = 1
b = 2
c = 2
Ожидаемый вывод:
expected = 1.666667
Ввод:
long long a = 1;
long long b = 2;
long long c = 2;
Ожидаемый вывод:
double expected = 1.666667;
Ввод:
long a = 1;
long b = 2;
long c = 2;
Ожидаемый вывод:
double expected = 1.666667;
Пояснение
1 + 2 + 2 = 5 and 5 / 3 ≈ 1.666667. Divide as decimals, not whole numbers.
Как подступиться
Сначала попробуйте сами, затем открывайте подсказки по одной.
Подсказка 1
Add the three values first, then spread the total across three equal parts.
Подсказка 2
Use ordinary arithmetic division so non-integer results are preserved.
Подсказка 3
Watch for languages that do integer division by default, since that would drop the fractional part.
Ожидаемая сложность
O(1) time, O(1) extra space
Ссылки
Это задание адаптировано для CodeUtility. Следуйте условию и ограничениям выше.