What will be the output of the following code? int f(int n) { static int a =…

PYQ Accenture Hiring Assessment 2024

What will be the output of the following code?

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

int main()
{
    printf("Result:%d", f(5));
    return 0;
}
  1. A.

    19

  2. B.

    9

  3. C.

    12

  4. D.

    18

Attempted by 90 students.

Sign up free to check your answer

Sign up free

Explore the full course: Cdac C Cat Complete Preparation

Loading lesson…