I see there a lot of good answer already published. However, I am posting this answer, which may help you in the future when you engage in more complex recursion.
Whenever you find something about recursion, try mathematically solving it first on your laptop. A good approach starts with the base case.
The base block of the fun(k) function is fun(1) , which returns 1 . So start with the following:
fun(1) = 1 // let read this, function fun(1) returns 1
Now for fun(2) , what will happen?
fun(2) = 2 + fun(1) = 2 + 1
I think it now makes sense why x = 5 !
source share