Skip to content

Instantly share code, notes, and snippets.

@jmramirezpro
Created February 26, 2016 12:50
Show Gist options
  • Save jmramirezpro/3b9cb5e10b36fd869a61 to your computer and use it in GitHub Desktop.
Save jmramirezpro/3b9cb5e10b36fd869a61 to your computer and use it in GitHub Desktop.
/*
* NumeroN.c
* Ejercicios del Podcast Codigo Fuente - Programa 023
* Escribe un programa que lea un número N mayor que 0 y
* que calcule la siguiente suma 1 + 2 + 3 + … + N
* Creado el 24 de feb. de 2016
* Author: jmramirez
*/
#include <stdio.h>
int main(void)
{
int numero;
int suma = 0;
printf("Introduce un número: ");
scanf("%d", &numero);
while (numero > 0) {
suma = suma + numero;
numero = numero - 1;
}
printf("El resultado de la suma es: %d\n", suma);
return (0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment