Skip to content

Instantly share code, notes, and snippets.

@TheSecretSquad
Created November 16, 2014 20:20
Show Gist options
  • Save TheSecretSquad/963df5b3e9b9420ede31 to your computer and use it in GitHub Desktop.
Save TheSecretSquad/963df5b3e9b9420ede31 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
int main ()
{
unsigned long previousNthFibNumber = 0,
nthFibNumber = 1,
sum = 0,
numEntered;
std::cout << "Enter a number to count to using a Fibonacci Sequence: ";
std::cin >> numEntered;
for (sum; sum < numEntered; sum = previousNthFibNumber + nthFibNumber)
{
cout << sum << endl;
previousNthFibNumber = nthFibNumber;
nthFibNumber = sum;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment