GATE Assistant

Past questions › Computer Science and Information Technology › GATE 2021 set2

GATE 2021 set2 · CS · NAT · 2 marks · Programming and Data Structures › Recursion

GATE 2021 set2 Computer Science and Information Technology question: Consider the following ANSI C program. code The output of the program upon execution is

Consider the following ANSI C program.

#include <stdio.h>

int foo(int x, int y, int q)
{
    if ((x <= 0) && (y <= 0))
        return q;
    if (x <= 0)
        return foo(x, y-q, q);
    if (y <= 0)
        return foo(x-q, y, q);
    return foo(x, y-q, q) + foo(x-q, y, q);
}

int main()
{
    int r = foo(15,15,10);
    printf("%d", r);
    return 0;
}

The output of the program upon execution is ______

Show answer

Official answer: 60

Practise this question with exam-style marking

Discussion

No discussion yet.

Join the discussion