For fun, and a love of numbers, I wrote a very simple program that desplays all the numbers in the Fibonacci sequence upto x number. It of course ends the loop if the number becomes larger then the the used variable type.
In my program I use unsigned __int64 because out of all the type I found it allowed the largest number. My question is:
How can I allow for my program to reach values larger than the 93rd number in the sequence?
#include <iostream>
usingnamespace std;
unsigned __int64 x = 1;
unsigned __int64 y;
unsigned __int64 z;
int a;
int b;
int c=0;
int main()
{
cout << "Find how many numbers? \n";
cin >> a;
for (b=0;b<a;b++)
{
if (b%3==0)
{
c++;
cout <<"\n" << c << ") ";
}
cout << x << " ";
z = y;
y = x;
x +=z;
if (x < z)
{
cout << "\nMaxed out at " << b+1;
b = a;
}
} // for
cin.get();
cin.get();
}
I dont think there's any way to do that other than create a class which can handle large "numbers" (individual digits stored as vectors, perhaps). Its one of the projects I'm working on atm.
As for types, that is actually a compiler-dependant question. You should be able to #include <cstdint> to get a complete range of types. See Wikipedia for more: http://en.wikipedia.org/wiki/Stdint.h