GATE CS 2014 Set 3 — Question 41

Multiple choice 2 marks Question 41 2014

Question 41

MCQ 2 marks · −0.66 Programming and Data Structures

Consider the following function:

int f(int n) {
    static int r = 0;
    if (n <= 0) return 1;
    if (n > 3) {
        r = n;
        return f(n - 2) + 2;
    }
    return f(n - 1) + r;
}

What is the value of f(5)?

Answers and explanations are free — they just need an account.

Where this question comes from

Source: GATE 2014 Computer Science and Information Technology, Set 3, Q41 (set and question number approximate)