eXorithm – Execute Algorithm: View / Run Algorithm calculate_median

Logo Beta

function calculate_median ($numbers

{

  sort$numbers);

  $c = count$numbers) - 1;

  if ($c%2) {

    $b = round$c/2);

    $a = $b-1;

    return ($numbers$b] + $numbers$a]) / 2 ;

  } else {

    return $numbers[($c/2)];

  }