You are using a version without Ads of this website. Please, consider donating:

### Problem with Fibonacci assignment

im having difficulty understanding this assignment

 Write a program that will trace how Fibonacci numbers are generated recursively (for any N) and display the trace in the following way :

 ``1234567891011121314151617181920`` ``````Example (N=4): Entering level 0 Entering level 2 Entering level 4 Exiting level 4 Entering level 3 Exiting level 3 Exiting level 2 Entering level 1 Entering level 3 Exiting level 3 Entering level 2 Entering level 4 Exiting level 4 Entering level 3 Exiting level 3 Exiting level 2 Exiting level 1 Exiting level 0``````

i dont see how the level relates...

heres my code:
 ``12345678910111213141516171819202122232425262728293031323334`` ``````#include #include #include using namespace std; int fib(int n); int main() { for(int i=1; i<=10; i++) { cout << fib(i) << endl; } system("PAUSE"); return 0; } /***********functions*************/ int fib(int n) { if(n<=0) { //cout << "-" << endl; return 0; } if(1 == n) { return 1; } else { return fib(n-1) + fib(n-2); } }``````
The problem should've been more informative. Anyways this is all what I can do..

 ``1234567891011121314151617181920212223242526272829303132333435`` ``````void FillTabs(int level) { //As many tabs as the level for (int i=0;i
Topic archived. No new replies allowed.