Advertisement
luizaspan

Fibonacci Sequence

May 12th, 2015
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.30 KB | None | 0 0
  1. // calcular os primeiros n números da sequência de fibonacci
  2. // f_n = f_(n-1) + f_(n-2)
  3.  
  4. #include <stdio.h>
  5.  
  6. int main(void)
  7. {
  8.   long i,a,b,c;
  9.  
  10.   a=0;
  11.   b=1;
  12.   c=1;
  13.  
  14.   for (i=0;i<=100;i++)
  15.     {
  16.       c=a+b;
  17.       a=b;
  18.       b=c;
  19.  
  20.       printf("%d\n",c);
  21.     }
  22.  
  23.   return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement