ง่าย 0 ข้อที่แก้แล้ว อัตราผ่าน 0%

Array Average

Compute the average of a list of numbers.

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.

เงื่อนไข

1 ≤ length ≤ 100,000; -10⁹ ≤ each value ≤ 10⁹

ตัวอย่าง

ตัวอย่างที่ 1
อินพุต:
numbers = [2, 4, 6]

ผลลัพธ์ที่คาดหวัง:
expected = 4.0
อินพุต:
std::vector<long long> numbers = {2, 4, 6};

ผลลัพธ์ที่คาดหวัง:
double expected = 4.0;
อินพุต:
long[] numbers = new long[] {2, 4, 6};

ผลลัพธ์ที่คาดหวัง:
double expected = 4.0;

คำอธิบาย

(2 + 4 + 6) / 3 = 4.

ตัวอย่างที่ 2
อินพุต:
numbers = [1, 2]

ผลลัพธ์ที่คาดหวัง:
expected = 1.5
อินพุต:
std::vector<long long> numbers = {1, 2};

ผลลัพธ์ที่คาดหวัง:
double expected = 1.5;
อินพุต:
long[] numbers = new long[] {1, 2};

ผลลัพธ์ที่คาดหวัง:
double expected = 1.5;

คำอธิบาย

(1 + 2) / 2 = 1.5; divide as decimals.

แหล่งอ้างอิง

โจทย์นี้ปรับให้เหมาะกับ CodeUtility กรุณาทำตามคำชี้แจงและข้อจำกัดด้านบน

เรียนรู้จากคนอื่น

แนวทางจากชุมชน

ยังไม่มีวิธีทำที่เผยแพร่ ลองแก้โจทย์นี้เพื่อแชร์วิธีแรก