#K54112. Average of Subarrays
Average of Subarrays
Average of Subarrays
You are given an array of integers. Your task is to compute the average of every contiguous subarray of length 3. For each subarray starting at index i, calculate:
\(average_i = \frac{a_i + a_{i+1} + a_{i+2}}{3}\)
Round each average to one decimal place and output all resulting averages in order.
Note: The input will always contain at least 3 integers.
inputFormat
The first line contains an integer n
representing the number of elements in the array.
The second line contains n
space-separated integers.
outputFormat
Output the averages of every contiguous subarray of length 3, rounded to one decimal place, separated by a space.
## sample5
1 2 3 4 5
2.0 3.0 4.0