← 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
- Initialize sum and count variables.
- Iterate through the array:
- Add each element to sum.
- Increment count for each element.
- 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.