Created
April 23, 2013 01:15
-
-
Save jmcph4/5440059 to your computer and use it in GitHub Desktop.
Very simple Fibonacci sequence generator in C++. It accepts a single command-line parameter, which is the quantity of numbers to generate.
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
| #include <cstdlib> | |
| #include <iostream> | |
| using namespace std; | |
| int main(int argc, char** argv) | |
| { | |
| int i = 0; | |
| int n = atoi(argv[1]); | |
| int f[n]; | |
| if(argc == 2) | |
| { | |
| for(i = 0; i <= n; i++) | |
| { | |
| if(i > 2) | |
| { | |
| f[i] = f[i-1] + f[i-2]; | |
| } | |
| else | |
| { | |
| f[i] = 1; | |
| } | |
| cout << abs(f[i]) << endl; | |
| } | |
| } | |
| else | |
| { | |
| cerr << "Insufficient command-line parameters given." << endl; | |
| } | |
| system("pause"); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment