Solved

# Help!!!(Anyone that truly understands recursion)

Posted on 2003-03-02

This was a question from my lab at class. It's over, but I still don't quite understand it. They say if I can understand this question I know recursion. can someone please explain how this works.

Provided below is a function. Simply stick it in main and have an int passed into it and the fun begins.

void f(int n) {

if (n > 1) {

cout << 'a';

f(n/2);

cout << 'b';

f(n/2);

}

cout << 'c';

}

The function output of the code is easy when the numbers passed into is 1,2, or 3. However, I get losts when it starts going to 4. If anyone can help me please tell me the output of this code when a 4 is passed into the funciton. If you can please tell me how you got it. If possible explain with values of 5,6,7 as well. Thank You.