Print the average higher than 30 students [closed]

-1

Write a program in PHP that loads in an array

I have this:

} 

for ($x=0;$x<count($valores);$x++) 
    
asked by juanlopez89 17.06.2017 в 02:26
source

1 answer

-1
<?php
function MediaPositiva ($arr,$mediaFunc)
{
  $retArr = array();
  for ($i=0; $i <count($arr) ; $i++)
  {
    if($arr[$i] >$mediaFunc)
    {
      array_push($retArr,$arr[$i]);
    }
  }
  return $retArr;
}

$res = array();
$valores = array();
for ($x=0;$x<30;$x++)
{
    $num_aleatorio = rand(1,10);
    array_push($valores,$num_aleatorio);
  }

$media = array_sum($valores) / count($valores);

$res = MediaPositiva($valores,$media);
echo '<h4>Las notas mayores a '.$media.' son: </h4><br>';
$y = 1;
for ($i=0; $i <count($res) ; $i++)
{
  echo '<label>'.$y.'.-Esta nota es de:  '.$res[$i].'</label><br>';
  $y++;
}

echo '<h4>Se descartaron '.(count($valores) - count($res)).' notas</h4>';
 ?>

I recommend that you add more fuel to the next one. Do not forget to mark it as correct if it serves you.

    
answered by 17.06.2017 / 03:01
source