Recursive Problem Help

Nov 11, 2021 at 1:36pm
Hello guys, I just need some help with the code below.
I just need to fix it by successfully printing the expected output below.
My output:
123456789101112

Expected Output:
121110987654321

#include <iostream>

using namespace std;
void recursive (int n) 
{
    if (n == 0)
    return;
    recursive (n-1);
    cout <<  n;
}

int main()
{
recursive(12);

    return 0;
}
Last edited on Nov 11, 2021 at 1:53pm
Nov 11, 2021 at 1:47pm
Your output is the expected output. What is the problem?
Nov 11, 2021 at 1:53pm
My output result is 123456789101112 and my output should print the numbers reversely. It should be 121110987654321. I just got a typo. My apologies for that. I just updated my concern above.
Last edited on Nov 11, 2021 at 1:54pm
Nov 11, 2021 at 1:56pm
Print your number cout << n; BEFORE you recurse to the next lower recursive (n-1);
Nov 11, 2021 at 1:58pm
Thanks. I appreciate that.
Last edited on Nov 11, 2021 at 1:58pm
Topic archived. No new replies allowed.