case n = 4 the values follows like that n = 4 when n enter the function, n=3 after the first recursion call, and follow to 2, 1, 0, 1, 2, 1, 0

Fibonacci(4) = 3

And now my doubt, n becomes 1 after the third recursion call, why it continues in the function? If in the else block I cut the fibonacci( n - 2 ), like return fibonacci( n - 1); the recursion stops when n=1, but with a sum like fibonacci( n - 1 ) + fibonacci( n - 2 ); the recursion continues if n=1 or 0 .

unsigned long fibonacci( unsigned long n ) { if ( n == 0 || n == 1 ) // base case return n; else // recursive case return fibonacci( n - 1 ) + fibonacci( n - 2 ); }

thanks in advance,

Ingo Sousa

This post has been edited by **ingombs**: 03 February 2009 - 09:16 AM