#K90212. Calculate Statistics of an Array
Calculate Statistics of an Array
Calculate Statistics of an Array
You are given an array of numbers. Your task is to compute and output the minimum value, maximum value, and the average value of the array. If the array is empty, simply output None
. Note that the average should be printed without any trailing decimal point if it is a whole number.
The input is provided via standard input. The first line contains a single integer n indicating the number of elements in the array. If n is 0, the array is empty. Otherwise, the second line contains n space-separated numbers.
The output should be printed on standard output in the format:
min max average
For example, if the input array is [1, 2, 3, 4, 5]
then the output should be: 1 5 3
(since the average is \(\frac{1+2+3+4+5}{5}=3\)).
inputFormat
The input is read from stdin and is structured as follows:
- The first line contains a single integer n that indicates the number of elements in the array.
- If n > 0, the second line contains n space-separated numbers representing the array elements. If n is 0, there is no second line.
outputFormat
The output should be written to stdout:
- If the array is empty (i.e. n = 0), output:
None
. - Otherwise, output three values separated by a single space: the minimum value, the maximum value, and the average value.
If the computed average is a whole number, output it as an integer without a decimal point.
## sample5
1 2 3 4 5
1 5 3