a simple recursion question

hi ims orry bout asking for code on other problem i was just so lost, bcause my suckie teacher tried to make us do it WITHOUT teaching us recursion. i tried reading the recursion tutorial on the site it cleared some issues up, but not all, ok this is the only problem with recursion i have,

lets say this....

fibonacci numbers 0, 1, 1,2,3,5,8,13,21.....etc

it adds previous values to get the next value...

now, the code for the recursion in my book says....

unsigned long fibonacci (unsigned long){

if ( n == 0 || n ==1) // i understand this , the base case

return n; // i get this too.

else

return fibonacci (n - 1 ) + fibonacci ( n - 2 );

}

in line... return fibonacci (n - 1 ) + fibonacci ( n - 2 ); why wouldnt it add the two rpevious values to make the recursion? why subtract??

Re: a simple recursion question

Quote:

*Originally posted by tetra *

**hi ims orry bout asking for code on other problem i was just so lost, bcause my suckie teacher tried to make us do it WITHOUT teaching us recursion.**

maybe your teacher is smarter than you think; it is horribly inefficient to calculate fibonacci numbers with a recursive loop like you just posted.