Skip to content

Instantly share code, notes, and snippets.

@jsfaint
Created May 27, 2014 03:23
Show Gist options
  • Save jsfaint/712d4882417978cd50fd to your computer and use it in GitHub Desktop.
Save jsfaint/712d4882417978cd50fd to your computer and use it in GitHub Desktop.
#include <cstdio>
const int max = 65000;
const int lineLength = 12;
void fibonacci( int max )
{
if ( max < 2 )
return;
printf("0 1 ");
int v1 = 0, v2 = 1, cur;
for ( int ix = 3; ix <= max; ++ix ) {
cur = v1 + v2;
if ( cur > ::max ) break;
printf("%d ", cur);
v1 = v2;
v2 = cur;
if (ix % lineLength == 0)
puts("");
}
}
void fibonacci( int );
int main()
{
printf("Fibonacci Series: 20\n");
fibonacci(20);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment