#C14935. Median Computation
Median Computation
Median Computation
Given a list of n integers, your task is to compute the median of the list. The median is defined as the middle value when the list is sorted. If the number of integers (n) is odd, the median is the middle element. If n is even, the median is given by \( \frac{a+b}{2} \), where \(a\) and \(b\) are the two middle numbers after sorting.
For example, if the input is [2, 5, 1, 7, 3], the sorted array is [1, 2, 3, 5, 7] and the median is 3. If the input is [1, 6, 2, 4], the sorted array is [1, 2, 4, 6] and the median is \( \frac{2+4}{2} = 3.0 \).
inputFormat
The input is given from stdin in the following format:
n x1 x2 x3 ... xn
Here, n
is an integer representing the number of elements, followed by n
integers separated by spaces.
outputFormat
Output the median value to stdout. If the list has an odd number of elements, output the integer median. If the list has an even number of elements, output the median as a floating-point number with one decimal place.
## sample5
2 5 1 7 3
3
</p>