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

Printable View

- 09-18-2001SnoFinKfind median of numbers
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 - 09-18-2001Nick
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}