← Back

Calculate the sum and average of elements in an array.

Given an array of integers, find the sum and average of its elements.

Algorithm

  1. Initialize sum and count variables.
  2. Iterate through the array:
  3. Calculate average as sum / count.

Time Complexity

The time complexity of this algorithm is O(n), where n is the number of elements in the array.