#K77992. Average of Positive Numbers
Average of Positive Numbers
Average of Positive Numbers
You are given a list of integers. Your task is to calculate the average of all positive numbers in the list. If there are no positive numbers, the answer should be 0.
More formally, if the list contains positive numbers \(p_1, p_2, \dots, p_k\), you are to compute:
\(\frac{p_1+p_2+\cdots+p_k}{k}\)
If \(k=0\) (i.e. there are no positive numbers), output 0.
inputFormat
The input is read from stdin
and consists of two lines:
- The first line contains a single integer \(n\), representing the number of elements in the list.
- The second line contains \(n\) space-separated integers.
outputFormat
Output the average of the positive numbers as a floating-point number in stdout
. If there are no positive numbers, output 0.
4
1 -2 3 4
2.6666666666666665