Advertisement
FAMDS

QUESTÃO14

Sep 19th, 2019 (edited)
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.33 KB | None | 0 0
  1. int fatorial (int n)
  2. {
  3. if (n == 0)
  4. return 1;
  5. else if (n<0){
  6. printf("\nErro: fatorial de numero negativo!\n");
  7. getch();
  8. exit(0);
  9. }
  10. return n*fatorial(n-1);
  11. }
  12. int main(void)
  13. {
  14. int n, fat=1;
  15. printf("Digite um numero inteiro:");
  16. scanf("%d", &n);
  17. fat=fatorial(n);
  18. printf("\n\nO fatorial de %d eh: %d", n,
  19. fat);
  20. getch();
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement