Advertisement
FelipeNeto2

FIBONACCI (via vetor)

May 17th, 2019
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.42 KB | None | 0 0
  1. #include <stdio.h>
  2. int fibo(int n){
  3.   int fib[n];
  4.  
  5.   fib[0] = 1;
  6.   fib[1] = 1;
  7.  
  8.   if(n==1){
  9.     return 1;
  10.   }else if(n==2){
  11.     return 1;
  12.   }else{
  13.     for(int i = 1; i<n; i++){
  14.       fib[i]=fib[i-1]+fib[i-2];
  15.     }
  16.    
  17.     return fib[n-1];
  18.   }  
  19. }
  20.  
  21. int main(void) {
  22.   int n, f;
  23.  
  24.   printf("Digite o termo da sequência: ");
  25.   scanf("%d", &n);
  26.  
  27.   f = fibo(n);
  28.  
  29.   printf("\n%d", f);
  30.  
  31.   return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement