Легко Решена: 1 Процент решений: 100.0%

Average of Three

Average three whole numbers.

Чему вы научитесь

  • Add numbers and divide by their count
  • Avoid integer division surprises
  • Return a decimal result

Условие

Показать перевод

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

Примеры

Пример 1
Ввод:
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.

Пример 2
Ввод:
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. Следуйте условию и ограничениям выше.

Учитесь у других

Решения сообщества

Внимание, спойлер: ниже 1 полное решение Попробуйте сначала решить сами. Вы всегда можете посмотреть код других и AI-обзоры. Войдите и решите задание, чтобы присоединиться к обсуждению.