You have to be the compiler and computer. Write down the stack as you go:
Enter main, call fun with 5.
In fun, 5 is greater than 0, so
I first decrement 5 to 4, then call fun again
Here if you are writing, I would move to the side and "start a new stack"
I enter fun with 4, which is greater than 0
I decrement 4 to 3, then call fun again
Repeat
I enter fun with 3, which is greater than 0
I decrement 3 to 2, then call fun again
Repeat again
I enter fun with 2, which is greater than 0
I decrement 2 to 1, then call fun again
And once more
I enter fun with 1, which is greater than 0
I decrement 1 to 0, then call fun again
And enter for the last time, this time
I enter fun with 0, which is not greater than 0
I return
Now you go back to where you were:
I enter fun with 1, which is greater than 0
I decrement 1 to 0, then call fun again
I print out 0
On print commands, write that in yet another space, which now only contains "0". continue the function:
I enter fun with 1, which is greater than 0
I decrement 1 to 0, then call fun again
I print out 0
I decrement 0 to -1 and call fun again
Here's another stack, but -1 is not greater than 0, so it does nothing. We go back into the function:
I enter fun with 1, which is greater than 0
I decrement 1 to 0, then call fun again
I print out 0
I decrement 0 to -1 and call fun again
I print out -1
And we finish this stack. We go back to an older stack (we just finished entering fun with 1, so look for the stack that ends with "decrement to 1 and call fun again"):
I enter fun with 2, which is greater than 0
I decrement 2 to 1, then call fun again
I print out 1
I decrement 1 to 0, then call fun again
Calling fun(0)
does nothing, so we return and continue:
I enter fun with 2, which is greater than 0
I decrement 2 to 1, then call fun again
I print out 1
I decrement 1 to 0, then call fun again
I print out 0
Then we go to the next oldest stack (we just finished entering fun with 2, so look for the stack that ends with "decrement to 2 and call fun again"):
I enter fun with 3, which is greater than 0
I decrement 3 to 2, then call fun again
I print out 2
I decrement 2 to 1, then call fun again
Here's an important time saver! We've already called fun(1)
once before, there's no need to really go through it again. What did fun(1)
print out? Look up and you'll see it added "0-1" to the output, so save time and just append that.
This continues until you have finished. It's a lot of work, but writing down your current stacks is the easiest way to complete it. For the sake of trying to keep this already long answer short, the rest is up to you. :)