Created
February 26, 2016 12:50
-
-
Save jmramirezpro/e49634acd717dade1830 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
/* | |
* 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