PRF192_-_SP_2025_-_PE_-_CT_3484.webp
SN1

PRF192_-_SP_2025_-_PE_-_CT_3484.webp

  • Media owner SN1
  • Ngày thêm
Problem 3
PRF192 - Examination 01
[3 Points]
The median of an array is computed as follow:
• Sort the array in ascending order.
• If the array has an odd number of elements, the median is the middle element.
⚫ If the array has an even number of elements, the median is the average of the two middle
elements.
Your task here is to write a program to find the median of the given array.
Input
The first line contains the number of elements, n.
The second line contains n space-separated elements: {a1, .., an}.
Constraint
⚫ 1<n<100
⚫a; EN, for 1≤i≤n.
⚫ -3*10°<a≤3*10%, for 1≤i≤n.
Output
One number, rounded to two decimal places, representing the median of given array.
Sample Input
Output Explanation
testcase
Testcase 15
2.00
5 19 1 2
Testcase 2 6
8 3 2 1 6 9
4.50
Sort the array in ascending order:
1 1 2 5 9
Since number of elements is odd, the
median is the middle element: 2.00
Sort the array in ascending order:
1 2 3 6 8 9
Since number of elements is even,
the median is the average of the two
middle elements: (36)/2 4.50
=
Chưa có bình luận nào.

Thông tin

Category
PRF192
Thêm bởi
SN1
Ngày thêm
Lượt xem
87
Lượt bình luận
0
Rating
0.00 star(s) 0 đánh giá

Share this media

Back
Bên trên Bottom