Skip to content

Instantly share code, notes, and snippets.

@krysseltillada
Created May 5, 2015 19:17
Show Gist options
  • Save krysseltillada/fe655d33ee8a62fd6be5 to your computer and use it in GitHub Desktop.
Save krysseltillada/fe655d33ee8a62fd6be5 to your computer and use it in GitHub Desktop.
fibonacci number generator
#include <iostream>
int main()
{
int num1 = 1, num2 = 1, max_num = 0, sum = 0, counter = 0;
cout << "enter a number of values to generate a fibonacci numbers: ";
cin >> max_num;
cout << num1 << endl
<< num2 << endl;
while (counter < max_num){
sum = num1 + num2;
cout << sum << endl;
num1 = sum;
counter++;
if (counter >= max_num){
break;
}
sum = num1 + num2;
cout << sum << endl;
num2 = sum;
counter++;
}
system("pause");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment