Advertisement
estephane

Recursividade

Sep 18th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.65 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5.  
  6. /*
  7. int fibonacci(int i)
  8. {
  9.     if(i == 1) return 1;
  10.     if(i == 2) return 1;
  11.     return fibonacci(i-1)+ fibonnaci(i-2);
  12. }
  13.  
  14.  
  15. int main()
  16. {
  17.     int i=0, resultado = 0;
  18.     printf("Digite um valor:");
  19.     scanf("%d",&i);
  20.     resultado = fibonnaci(i);
  21.     printf("%d \n ", resultado);
  22.     return 0;
  23. }
  24.  
  25. */
  26.  
  27.  
  28. int fatorial(int n)
  29. {
  30.     if (n == 1)
  31.     return n;
  32.     return n * fatorial(n-1);
  33. }
  34.  
  35. int main()
  36. {
  37.     int n=0, resultado=0;
  38.     printf("Digite um valor:");
  39.     scanf("%d",&n);
  40.     resultado = fatorial(n);
  41.     printf("%d \n ", resultado);
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement