Skip to the task
Layout
Back to classic view

You are looking at: Practice test 1. Your place is still lesson 5, task 1: Functions.

CHECKTask 10 of 17 · step 3: Questions 7–12

f(6) and f(5)

What does f(6) return? And f(5)?

int f(int n) {
    if (n == 0) {
        return 0;
    }
    return n + f(n - 2);
}
Stuck?

f(6) = 6 + 4 + 2 + 0 = 12. f(5) never reaches 0 and calls itself until the stack runs out (stack overflow). (Topic 5)