Skip to content

Instantly share code, notes, and snippets.

@jmramirezpro
Created February 26, 2016 12:50
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 jmramirezpro/e49634acd717dade1830 to your computer and use it in GitHub Desktop.
Save jmramirezpro/e49634acd717dade1830 to your computer and use it in GitHub Desktop.
/*
* NumeroRepetido.c
* Ejercicios del Podcast Codigo Fuente - Programa 023
* Escribe un programa que lea de forma repetida un número N.
* Para cada número leído, el programa calculará la suma 1 + 2 + 3 + … + N.
* Una vez mostrado el resultado preguntará al usuario si desea continuar;
* si se introduce el valor s el programa continuará, en caso contrario finalizará.
* Creado el 24 de feb. de 2016
* Author: jmramirez
*/
#include <stdio.h>
int main(void)
{
int numero;
int suma;
int j;
char opcion;
do{
printf("Introduce el número (debe ser mayor que 0)");
scanf("%d", &numero);
suma = 0;
for (j = 1; j < numero; j++) {
suma = suma + j;
}
printf("La suma es %d\n", suma);
printf("¿Deseas continuar? [s/n]:");
scanf("\n%c", &opcion);
}while (opcion == 's');
return (0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment