Fomula

 BBS: Inland Empire Archive
Date: 08-13-92 (14:35)             Number: 165
From: RICK PEDLEY                  Refer#: NONE
  To: STEVE CRAVER                  Recvd: NO  
Subj: Fomula                         Conf: (2) Quik_Bas
 On 08-13-92 Steve Craver wrote to All...

 SC> Does anyone know the correct formula for finding the MEDIAN
 SC> of an array of numbers? Not the average, just the median.

Assuming the numbers are in an array, first sort the numbers by
whatever method you wish.  Then divide the number of elements
by 2 and round up; that element lies in the middle.  For example,
if the number of elements is 13, then

DEFINT A-Z
Els = 13
IF Els AND 1 THEN            'Tests to see if Els is odd
   Median! = N(Els\2 + 1)    'The value right in the middle
ELSE
   Median! = (N(Els\2) + N(Els\2 + 1))/2
ENDIF

The middle value in the sorted list is the median.  If Els is
even, there is no middle value, so the two values on either
side of the halfway point are averaged.\


... OFFLINE 1.40

--- Maximus 2.01wb
 * Origin: The BULLpen BBS * Intel 14.4EX (613)549-5168 (1:249/140)
Outer Court
Echo Basic Postings

Books at Amazon:

Back to BASIC: The History, Corruption, and Future of the Language

Hackers: Heroes of the Computer Revolution (including Tiny BASIC)

Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution

The Advent of the Algorithm: The Idea that Rules the World

Moths in the Machine: The Power and Perils of Programming

Mastering Visual Basic .NET