I need some help with understanding this recursive function. It is returning 101 when n = 5 but I do not understand why. Here is the function:
string RecursiveMystery(int n) {
string s = "1";
if (n % 2 == 0) {
s = "0";
}
if (n < 2) {
return s;
}
return RecursiveMystery(n / 2) + s;
So when RecursiveMystery(5), it should go into the end return function RecursiveMystery(5 / 2) which is equal to 0 + 1 which is 01 (because s = 1 at the time of RecursiveMystery(5)). I'm stuck with understanding how it is still returning 101.
101(if printed)