Advertisement
eddiehy

F_class_use_for

Nov 29th, 2015
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.25 KB | None | 0 0
  1. #include <stdio.h>
  2. int Fib(int n)
  3. {
  4. int a1, a2=0, a3=1, i;
  5. if(n==1)
  6. {return 0;}
  7. else if(n<=2)
  8. {return 1;}
  9. for(i=3; i<=n; i++)
  10. {
  11. a1=a2;
  12. a2=a3;
  13. a3=a1+a2;
  14. }
  15. return a3;
  16. }
  17.  
  18. int main()
  19. {
  20. printf("%d",Fib(6));
  21. return 0;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement