Tutte le sfide
Facile 1 risolta 100.0% di accettazione

Average of Three

Average three whole numbers.

Problema

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.

Vincoli

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

Esempi

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

Output atteso:
expected = 5.0
Input:
long long a = 2;
long long b = 4;
long long c = 9;

Output atteso:
double expected = 5.0;
Input:
long a = 2;
long b = 4;
long c = 9;

Output atteso:
double expected = 5.0;

Spiegazione

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

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

Output atteso:
expected = 1.666667
Input:
long long a = 1;
long long b = 2;
long long c = 2;

Output atteso:
double expected = 1.666667;
Input:
long a = 1;
long b = 2;
long c = 2;

Output atteso:
double expected = 1.666667;

Spiegazione

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

Riferimenti

Questa sfida è adattata per CodeUtility. Segui la traccia e i vincoli sopra.

Impara dagli altri

Soluzioni della community

Attenzione spoiler: 1 soluzione completa sotto Prova prima a risolverla da solo. Puoi comunque sbirciare il codice degli altri sviluppatori e le recensioni AI. Accedi e risolvi la sfida per partecipare alla discussione.