2 comments:

  1. php
    $n=$_POST['num'];
    $str=$_POST['arr'];
    $x=explode(',',$str);
    if($n%2==0)
    {$median=$x[$n/2];
    $median1=$x[($n/2)-1];
    echo"$median and $median1";
    }
    else
    { $median=$x[(($n+1)/2)-1];
    echo"$median";
    }
    ?>

    ReplyDelete
  2. $str=$_POST['num'];
    $y=explode(",",$str);
    $n=sizeof($y);
    for($i=0;$i<=$n-1;$i++)
    {
    for($j=$i+1;$j<=$n-1;$j++)
    {
    if($y[$i]>$y[$j])
    {
    $temp=$y[$i];
    $y[$i]=$y[$j];
    $y[$j]=$temp;
    }

    }

    }

    if($n%2!==0)
    {
    $i=$n/2;
    echo "The median is: ".$y[$i];
    }
    else
    {
    $i=$n/2;
    $x=($y[$i]+$y[$i-1])/2;
    echo "The median is: ".$x;
    }

    ReplyDelete