The GATE Grind

GATE 2007 CS – Question 42

Programming and Data Structures · Recursion · 2 marks · Multiple choice

What is f(5)?

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;
}
  1. 5
  2. 7
  3. 9
  4. 18

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: (D) 18

Explanation

We are sorry we couldn't write detailed soluition for this, we are working on it!, please consider asking your own AI, its just 2-3 clicks with very minimum effort

More Recursion questions

All Recursion questions →