0
How would I make this algorithm not to terminate the program and allow me to write other numbers to calculate the factorial? I’ve tried putting one while
, or do while
, but in no way works, because it goes through the for
and the program soon closes..
#include <stdlib.h>
#include <stdio.h>
char resp;
int cont, num;
long fat=1;
main()
{
printf("Digite um numero para calcular o fatorial: ");
scanf("%d", &num);
for(cont=num;cont>1;cont--){
fat = fat*cont;
}
printf("%d! = %d", num, fat);
printf("\nContinuar [S/N]? ");
scanf("%c", &resp);
return 0;
}
The flow of your program is extremely similar to the one presented in the question I suggested as duplicate.
– Jefferson Quesado