Can someone please explain step by step how this function below works? For example, Fibo(6);

I really don't get it how it can end up with a result 8..

int Fibo(int x){

if(x==1 || x==2) return 1;

else return (Fibo(x-1)+Fibo(x-2));

}

I really don't get it how it can end up with a result 8..

int Fibo(int x){

if(x==1 || x==2) return 1;

else return (Fibo(x-1)+Fibo(x-2));

}

Fibo(1) and Fibo(2) return 1,

Fibo(3) returns (Fibo(2) + Fibo(1)) which so happens to be 1+1=2,

Fibo(4) returns (Fibo(3) + Fibo(2)) and you should already see what that is.

What's there not to understand? If you must, write down the whole sequence for Fib(6).

Fibo(3) returns (Fibo(2) + Fibo(1)) which so happens to be 1+1=2,

Fibo(4) returns (Fibo(3) + Fibo(2)) and you should already see what that is.

What's there not to understand? If you must, write down the whole sequence for Fib(6).

Topic archived. No new replies allowed.