find median of numbers

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 ...

  1. #1
    SnoFinK
    Guest

    find 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

  2. #2
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    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}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. find the median
    By JoeJoe in forum C++ Programming
    Replies: 9
    Last Post: 03-30-2008, 10:32 PM
  2. Logical errors with seach function
    By Taka in forum C Programming
    Replies: 4
    Last Post: 09-18-2006, 05:20 AM
  3. programming with random numbers
    By xstudent in forum C Programming
    Replies: 13
    Last Post: 05-21-2002, 01:36 AM
  4. Prime Numbers
    By cmangel518 in forum C++ Programming
    Replies: 13
    Last Post: 04-30-2002, 11:51 PM
  5. Line Numbers in VI and/or Visual C++ :: C++
    By kuphryn in forum C++ Programming
    Replies: 2
    Last Post: 02-10-2002, 09:54 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21