Untitled


SUBMITTED BY: jomich18

DATE: July 31, 2017, 8:33 a.m.

FORMAT: Text only

SIZE: 615 Bytes

HITS: 27726

  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int n, t1 = 0, t2 = 1, nextTerm = 0;
  6. cout << "Enter the number of terms: ";
  7. cin >> n;
  8. cout << "Fibonacci Series: ";
  9. for (int i = 1; i <= n; ++i)
  10. {
  11. // Prints the first two terms.
  12. if(i == 1)
  13. {
  14. cout << " " << t1;
  15. continue;
  16. }
  17. if(i == 2)
  18. {
  19. cout << t2 << " ";
  20. continue;
  21. }
  22. nextTerm = t1 + t2;
  23. t1 = t2;
  24. t2 = nextTerm;
  25. cout << nextTerm << " ";
  26. }
  27. return 0;
  28. }

comments powered by Disqus