Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Last active April 3, 2019 19:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/e7076e4ce6e416c1151ff4a7c03be349 to your computer and use it in GitHub Desktop.
Save parzibyte/e7076e4ce6e416c1151ff4a7c03be349 to your computer and use it in GitHub Desktop.
/*
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