Đề bài
Xem bản dịchReturn 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.
Ràng buộc
1 ≤ length ≤ 100,000; -10⁹ ≤ each value ≤ 10⁹
Ví dụ
Ví dụ 1
Đầu vào:
numbers = [2, 4, 6]
Kết quả mong đợi:
expected = 4.0
Đầu vào:
std::vector<long long> numbers = {2, 4, 6};
Kết quả mong đợi:
double expected = 4.0;
Đầu vào:
long[] numbers = new long[] {2, 4, 6};
Kết quả mong đợi:
double expected = 4.0;
Giải thích
(2 + 4 + 6) / 3 = 4.
Ví dụ 2
Đầu vào:
numbers = [1, 2]
Kết quả mong đợi:
expected = 1.5
Đầu vào:
std::vector<long long> numbers = {1, 2};
Kết quả mong đợi:
double expected = 1.5;
Đầu vào:
long[] numbers = new long[] {1, 2};
Kết quả mong đợi:
double expected = 1.5;
Giải thích
(1 + 2) / 2 = 1.5; divide as decimals.
Tham khảo
Thử thách này đã được điều chỉnh cho CodeUtility. Hãy làm theo đề bài và các ràng buộc ở trên.