Created
October 23, 2019 17:24
-
-
Save AdnanHussainTurki/3ee838509c0918dcd99df2b3998edec2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* @Author: Adnan | |
* @Date: 2019-09-16 07:55:45 | |
* @Last Modified by: Adnan | |
* @Last Modified time: 2019-10-23 22:52:57 | |
*/ | |
#include <iostream> | |
using namespace std; | |
// Method 1 | |
int main() { | |
cout << "PROGRAM: GENERATING FIBONACCI SEQUENCE"; | |
cout << "\n"; | |
cout << "========================================================="; | |
int inputOne; | |
cout << "\nEnter the integer for which you want to generate fibonacci sequence: "; | |
cin >> inputOne ; | |
int lastTerm = 1; | |
int secondLastTerm = 0; | |
// Printing fibonacci series | |
cout << "\n\n"; | |
cout << "0, 1, "; | |
for (int i = 2; i < inputOne; ++i) | |
{ | |
int thisTerm = lastTerm + secondLastTerm; | |
cout << thisTerm << ", "; | |
// cout << "\n\nAdding " << secondLastTerm << " + " << lastTerm << " = " << thisTerm << ", "; | |
secondLastTerm = lastTerm; | |
lastTerm = thisTerm; | |
} | |
cout << "\n\n"; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment