Created
August 6, 2019 05:46
-
-
Save parzibyte/458e83eac61e7a2fe0b9f1cb48ff021c 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 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