Advertisement
xlujiax

Edades

Sep 12th, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.93 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <title></title>
  5.     <link rel="stylesheet" type="text/css" href="estilo.css" media="">
  6. </head>
  7. <body>
  8.  
  9. </body>
  10. </html>
  11. <?php
  12.     function main(){
  13.         $cantidad=50;      
  14.         imprimir($cantidad);
  15.     }
  16.     function getEdades($can){
  17.         $sum = 0;
  18.         $cantMen = 0;
  19.         $cantMay = 0;
  20.         echo "Listado de Edades:<br>";
  21.         for ($i=0; $i < $can; $i++) {
  22.             $edad=rand(15,80);
  23.             echo "$edad<br>";
  24.             $sum += $edad;
  25.             if ($edad < 18){
  26.                 $cantMen += 1;
  27.             }else{
  28.                 $cantMay += 1;
  29.             }
  30.         }
  31.         $prom = $sum/$i;
  32.         echo "Cantidad de personas Menores: ".$cantMen;
  33.         echo "<br>";
  34.         echo "Cantidad de personas Mayores: ".$cantMay;
  35.         echo "<br>";
  36.         return $prom;
  37.     }
  38.     function imprimir($cantidad){
  39.         echo "Imprimir Resultados<br>";
  40.         echo "***********<br>";
  41.         echo "<br>";
  42.         $promedio = getEdades($cantidad);
  43.         echo "El promedio de edades es: ".$promedio;
  44.     }
  45.     //Mostrar Información de las funciones
  46.     main();
  47. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement