Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created October 16, 2019 19:41
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/91f9ec37b7223d3f66f963824d202a32 to your computer and use it in GitHub Desktop.
Save parzibyte/91f9ec37b7223d3f66f963824d202a32 to your computer and use it in GitHub Desktop.
#include <stdio.h>
/**
* Sumar valores de arreglo, es decir, obtener sumatoria
* usando el lenguaje C
*
* @author parzibyte
* https://parzibyte.me/blog
*
* */
int main() {
int numeros[] = {1, 2, 54, 28, 11, 96};
int longitud = sizeof numeros / sizeof numeros[0];
int sumatoria = 0;//Aquí vamos a almacenar cada valor
for (int x = 0; x < longitud; x++) {
int numeroActual = numeros[x];
// Sumar el número actual a la sumatoria
sumatoria = sumatoria + numeroActual;
// También se puede sumar de forma más simple:
// sumatoria += numeroActual;
}
printf("La sumatoria es: %d", sumatoria);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment