how would I go about finding the median of a set of numbers that the user enters? I posted something about a bubble sort ... but is there an easier way? thanks.
SnoFinK
This is a discussion on find median of numbers within the C++ Programming forums, part of the General Programming Boards category; how would I go about finding the median of a set of numbers that the user enters? I posted something ...
how would I go about finding the median of a set of numbers that the user enters? I posted something about a bubble sort ... but is there an easier way? thanks.
SnoFinK
A better way would be to chose a better sort algorithm such as
qsort, then sort.
Assuming that your data is x_1 ... x_n with x_i < x_{i+1}
if n is even then
median = x_{n/2} + x_{n/2 + 1}
else
median = x_{(n + 1)/2}