Skip to content

Instantly share code, notes, and snippets.

@jmcph4
Created April 23, 2013 01:15
Show Gist options
  • Select an option

  • Save jmcph4/5440059 to your computer and use it in GitHub Desktop.

Select an option

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.
#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