Learn
Exam

Calculate the Average of Array Elements

Difficulty
STARTER

Problem

Given an array numbers consisting of natural numbers, write a function solution that returns the average of the elements in numbers.


Constraints

  • Each element in numbers is a natural number not exceeding 500.
  • numbers is not empty, and its length does not exceed 100.
  • The result should be returned as a positive real number rounded to one decimal place.

Test Case

Test Case Number numbers return
1 [1] 1.0
2 [1, 2, 3, 4] 2.5
3 [151, 274, 333, 490, 500] 349.6

Explanation for Test Case 1

  • The total sum of elements in numbers is 1, and the count is 1, so the average is 1.0.

Explanation for Test Case 2

  • The total sum of elements in numbers is 10, and the count is 4, so the average is 2.5.

Explanation for Test Case 3

  • The total sum of elements in numbers is 1748, and the count is 5, so the average is 349.6.