Advertisement
R3v3rs3r

Fibonacci series C++

Sep 5th, 2023 (edited)
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.32 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     int n, nextTerm, t1=0, t2=1;
  7.     cout << "Enter term (>2): ";
  8.     cin >> n;
  9.     cout << t1 << "\n"<< t2 <<endl;
  10.     for(int i=3;i<=n;i++)
  11.     {
  12.         nextTerm=t1+t2;
  13.         cout << nextTerm << endl;
  14.         t1=t2;
  15.         t2=nextTerm;
  16.     }
  17.     return 0;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement