3 comments:

  1. $arr=array();
    $maxpos=1;
    $minpos=1;
    $max=$arr[0];
    $min=$arr[0];
    for($i=0;$i$arr[$i])
    {
    $min=$arr[$i];
    $minpos=$i+1;
    }
    }
    echo "Maximum:$max at $maxpos
    Minimum:$min at $minpos";

    ReplyDelete
  2. php
    $n=$_POST['num'];
    $str=$_POST['arr'];
    $x=explode(',',$str);
    $min=$x[0];
    $max=$x[0];
    $pos=0;
    $pos1=0;
    for($i=0;$i<$n;$i++)
    { if($x[$i]<$min)
    { $min=$x[$i];
    $pos=$i+1;
    }
    if($x[$i]>$max)
    { $max=$x[$i];
    $pos1=$i+1;
    }
    }
    echo"min element is:";
    print_r($min);
    echo"
    found at position:";
    print_r($pos);
    echo"
    max element is :";
    print_r($max);
    echo"
    found at position:";
    print_r($pos1);
    ?>

    ReplyDelete
  3. $str=$_POST['num'];
    $y=explode(",",$str);
    $n=sizeof($y);
    $min_value=$y[0];
    $min_pos=0;
    $max_value=$y[0];
    $max_pos=0;
    for($i=0;$i<=$n-1;$i++)
    {
    {
    if($y[$i]<$min_value)
    {
    $min_value=$y[$i];
    $min_pos=$i+1;
    }
    }
    }

    for($i=0;$i<=$n-1;$i++)
    {
    {
    if($y[$i]>$max_value)
    {
    $max_value=$y[$i];
    $max_pos=$i+1;
    }
    }
    }
    echo "The minimum value is:";
    print_r($min_value);
    echo "Position of the element is:";
    print_r($min_pos);
    echo "
    ";

    echo "The maximum value is:";
    print_r($max_value);
    echo "Position of the element is:";
    print_r($max_pos);

    ReplyDelete