Calculate and display huge fibonaci numbers

76 Views Asked by At

I'm pretty new to programming in general (just started uni), and can't find an answer (or maybe know to little to spot it) to my problem.

A few months ago I saw this video about a dynamic algorithm for calculating fibonaci numbers and just now I decided to try if I can do that myself. I have the algorithm (or as close to a proper one I could make on my own), but I don't know how to calculate and display HUGE numbers. 20 Digits is far too small. I'd like to try and go above the 200th fibonaci number, which is even larger than a 128bit integer can handle.

Here is my Code so far:

unsigned long long int dynFib(int n){

    unsigned long long int lastTwo[2] = {0,1};
    int counter = 0;
    unsigned long long int fib = 0;

    for(int i = 2; i <= n; i++){

        fib = lastTwo[0] + lastTwo[1];
        lastTwo[counter] = fib;
        counter = 1 - counter;
    }

    return fib;
}

I'd assume that some very large modifications would have to made, to actually get the result I'd like, I don't have a clue what those are though.

I'd really appreciate any help.

0

There are 0 best solutions below