Advertisement
Guest User

Untitled

a guest
Nov 14th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int n, t1 = 0, t2 = 1, nextTerm = 0;
  7.  
  8. cout << "Input number of terms: ";
  9. cin >> n;
  10.  
  11. cout << "Fibonacci Series: ";
  12.  
  13. for (int i = 1; i <= n; ++i)
  14. {
  15. // Prints the first two terms.
  16. if(i == 1)
  17. {
  18. cout << t1 << ", ";
  19. continue;
  20. }
  21. if(i == 2)
  22. {
  23. cout << t2 << ", ";
  24. continue;
  25. }
  26. nextTerm = t1 + t2;
  27. t1 = t2;
  28. t2 = nextTerm;
  29.  
  30. if(i == 10) {
  31. cout << nextTerm << endl;
  32. }
  33. else {
  34. cout << nextTerm << ", ";
  35. }
  36. }
  37. return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement