Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. Lista 5
  2. Questao 1
  3.  
  4. Letra a:
  5.  
  6. int funcao_fat(int x) {
  7. if(x==0) {
  8. return 1;
  9. } else {
  10. return (x * funcao_fat(x-1));
  11. }
  12. }
  13.  
  14. Letra b:
  15.  
  16. int fatorial (int n){
  17. int i, f;
  18. f = 1;
  19. for (i=2, i <= n; i++) {
  20. f= f*i;
  21. }
  22. return f;
  23. }
  24.  
  25. Letra c:
  26.  
  27. int funcao_fib(int i) {
  28. if(i==0) {
  29. return 0;
  30. }
  31. if(i==1) {
  32. return 1;
  33. } else {
  34. return (funcao_fib(i-1) + funcao_fib(i-2));
  35. }
  36. }
  37.  
  38. Letra d:
  39.  
  40. int fibonacci (int n) {
  41. int i, y, a=1, b=1;
  42. if(n>0) {
  43. return a;
  44. }
  45. if(n>=1) {
  46. return b;
  47. }
  48. for(i=2, i<= n, i++) {
  49. y = a+b;
  50. return y;
  51. a=b;
  52. b=y;
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement