Raphafrei

Recursive Factorial

Oct 9th, 2020
1,012
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.34 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. void main(){
  4.     int valor;
  5.  
  6.     printf("Insira um numero para obter seu fatorial:\n");
  7.     scanf("%d", &valor);
  8.  
  9.     printf("\n\nO fatorial de %d e: %d\n", valor, Fatorial(valor));
  10.  
  11.     system("pause");
  12. }
  13.  
  14. int Fatorial(int n){
  15.     if(n == 1)
  16.         return 1;
  17.     else
  18.         return n * Fatorial (n-1);
  19. }
Advertisement
Add Comment
Please, Sign In to add comment