Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created August 6, 2019 05:46
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/458e83eac61e7a2fe0b9f1cb48ff021c to your computer and use it in GitHub Desktop.
Save parzibyte/458e83eac61e7a2fe0b9f1cb48ff021c to your computer and use it in GitHub Desktop.
/*
Promedio de un arreglo de enteros en C
@author parzibyte
Visita: parzibyte.me/blog
*/
#include <stdio.h>
// Prototipo de la función
double promedioDeArreglo(int arreglo[], int cantidadDeElementos);
int main(){
int arreglo[] = {18, 19, 20, 19, 20};
int cantidadDeElementos = sizeof(arreglo) / sizeof(arreglo[0]);
double promedio = promedioDeArreglo(arreglo, cantidadDeElementos);
printf("El promedio es: %.2f\n", promedio);
}
double promedioDeArreglo(int arreglo[], int cantidadDeElementos){
double suma = 0;
for (int x = 0; x < cantidadDeElementos; x++){
suma = suma + arreglo[x];
}
return suma / cantidadDeElementos;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment