Problem
Return the arithmetic mean of the list: its sum divided by its length, as a decimal number.
Implement array_average(numbers).
Input
numbers: A non-empty list of integers.
Output
Return the average.
Constraints
1 ≤ length ≤ 100,000; -10⁹ ≤ each value ≤ 10⁹
Examples
Example 1
Input:
numbers = [2, 4, 6]
Expected output:
expected = 4.0
Input:
std::vector<long long> numbers = {2, 4, 6};
Expected output:
double expected = 4.0;
Input:
long[] numbers = new long[] {2, 4, 6};
Expected output:
double expected = 4.0;
Explanation
(2 + 4 + 6) / 3 = 4.
Example 2
Input:
numbers = [1, 2]
Expected output:
expected = 1.5
Input:
std::vector<long long> numbers = {1, 2};
Expected output:
double expected = 1.5;
Input:
long[] numbers = new long[] {1, 2};
Expected output:
double expected = 1.5;
Explanation
(1 + 2) / 2 = 1.5; divide as decimals.
References
This challenge is adapted for CodeUtility. Follow the statement and constraints above.