Fibonacci Function Question

Posted by DMan on Stack Overflow See other posts from Stack Overflow or by DMan
Published on 2010-05-01T20:38:02Z Indexed on 2010/05/01 20:47 UTC
Read the original article Hit count: 264

Filed under:
|

I was calculating the Fibonacci sequence, and stumbled across this code, which I saw a lot:

    int Fibonacci (int x)
{
    if (x<=1) {
        return 1;
    }
    return Fibonacci (x-1)+Fibonacci (x-2);
}

What I don't understand is how it works, especially the return part at the end: Does it call the Fibonacci function again? Could someone step me through this function?

© Stack Overflow or respective owner

Related posts about c++

Related posts about function