Question 1
What is the output of the following C function when called with fun(5)?
int fun(int n) {
if (n <= 1) return 1;
return n + fun(n - 1);
}Detailed Solution
fun(5) = 5 + fun(4) = 5 + 4 + fun(3) = 5 + 4 + 3 + fun(2) = 5 + 4 + 3 + 2 + fun(1) = 5 + 4 + 3 + 2 + 1 = 15.