Advertisement
homeworkhelp111

fibonacci

Feb 5th, 2022
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. int Fibonacci(int n) {
  2. int t1=0, t2=1,nextTerm;
  3. if (n < 0) {
  4. return -1;
  5. }
  6. if (n == 0) {
  7. return 0;
  8. }
  9. else if (n == 1) {
  10. return 1;
  11. }
  12. for (int i = 1; i <= n+1; ++i) {
  13. if (i == 1) {
  14. continue;
  15. }
  16. if (i == 2) {
  17. continue;
  18. }
  19. nextTerm = t1 + t2;
  20. t1 = t2;
  21. t2 = nextTerm;
  22. }
  23. return nextTerm;
  24. }
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement