Advertisement
nguyenhappy92

In ra n phân tử Fibonaci

Oct 9th, 2015
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. // In ra day so fibonaci
  2. // Khai bao cac ham thu vien neu co
  3. #include<stdio.h>
  4. #include<conio.h>
  5. long fibo(int n);
  6. void main()
  7. {
  8. int n;
  9. scanf("%d",&n);
  10. printf("%ld\t",fibo(n));
  11.  
  12. }
  13. long fibo(int n)
  14. {
  15. long f=0;
  16. long f1=1;
  17. long f2=1;
  18. if(n==2)
  19. return f1;
  20. else
  21. {
  22. for(int i=3;i<=n;i++)
  23. {
  24. f=f1+f2;
  25. f1=f2;
  26. f2=f;
  27. }
  28. return f;
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement