-
-
Save parzibyte/5a8215cdfe6ae5093427b53e00a59198 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# https://parzibyte.me/blog | |
$notas = []; | |
$cantidadNotas = 5; | |
for ($i = 0; $i < $cantidadNotas; $i++) { | |
echo "Ingrese la nota #" . ($i + 1) . ": "; | |
fscanf(STDIN, "%f", $nota); | |
// Agregar al arreglo | |
$notas[] = $nota; | |
} | |
// Ordenamos el arreglo | |
for ($i = 0; $i < $cantidadNotas; $i++) { | |
for ($j = 0; $j < $cantidadNotas - 1; $j++) { | |
if ($notas[$j] > $notas[$j + 1]) { | |
$temporal = $notas[$j]; | |
$notas[$j] = $notas[$j + 1]; | |
$notas[$j + 1] = $temporal; | |
} | |
} | |
} | |
// Lo imprimimos y a la vez vamos calculando el promedio | |
$sumatoria = 0; | |
echo "Notas de manera ascendente: \n"; | |
foreach ($notas as $nota) { | |
$sumatoria += $nota; | |
echo $nota . "\n"; | |
} | |
$promedio = $sumatoria / $cantidadNotas; | |
echo "Promedio: " . $promedio; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment