Skip to content

Beta · Data may be lost.Your data may be reset or lost.

GateBrew
← GATE CSE 2021 Set 2
Questions

Q49

NAT2 marksAlgorithms

Consider the following ANSI C\text{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 _________

Sign in to save attempts.

Solutions and discussion are hidden while you attempt this question. They open once you check or show the answer.