#C5254. Calculate Average and Median of Heights
Calculate Average and Median of Heights
Calculate Average and Median of Heights
You are given the heights of N students. Your task is to compute two statistical values based on these heights: the average and the median.
The average is defined as the sum of all heights divided by N, and the median is determined after sorting the list of heights. If N is odd, the median is the middle element; if N is even, the median is the average of the two middle elements. Both the average and median must be rounded to two decimal places.
Input: The first line contains an integer N (the number of students). The second line contains N space-separated integers representing the heights.
Output: Print two numbers: the average height and the median height, each rounded to two decimal places, separated by a space.
Note: Use stdin
to read input and stdout
to print output.
Mathematical Formulas:
- Average: \(\text{average} = \frac{\sum_{i=1}^{N} h_i}{N}\)
- Median: \(\text{median} = \begin{cases} h_{\frac{N+1}{2}}, & \text{if } N \text{ is odd} \\ \frac{h_{\frac{N}{2}} + h_{\frac{N}{2}+1}}{2}, & \text{if } N \text{ is even} \end{cases}\)
inputFormat
The first line of input contains a single integer N representing the number of students. The second line contains N space-separated integers representing the heights of the students.
outputFormat
Output two numbers separated by a space: the average height and the median height, both rounded to two decimal places.
## sample5
150 160 170 180 190
170.00 170.00
</p>