-
-
Save parzibyte/e7076e4ce6e416c1151ff4a7c03be349 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
/* | |
Promedio de valores de un arreglo en C# | |
@author parzibyte | |
*/ | |
using System; // Para ahorrar escribir System.Console.WriteLine ;) | |
class MainClass { | |
public static void Main (string[] args) { | |
// Nuestro arreglo | |
double[] calificaciones = {90, 98, 85, 95, 90, 80, 70, 100, 55}; | |
// Vamos a almacenar la sumatoria | |
double sumatoria = 0; | |
// Lo recorremos con un foreach | |
foreach(double calificacion in calificaciones){ | |
// Ir agregando la calificación a la sumatoria | |
sumatoria += calificacion; | |
} | |
// El promedio resulta de dividir la sumatoria entre la cantidad de elementos | |
double promedio = sumatoria / calificaciones.Length; | |
Console.WriteLine("Promedio: " + promedio); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment