Recursive Programs questions

Q23

GATE CS 2021 CS-2RecursionNAT1 mark
Consider the following ANSI C function:
int SomeFunction(int x, int y)
{
    if ((x == 1) || (y == 1)) return 1;
    if (x == y) return x;
    if (x > y) return SomeFunction(x - y, y);
    if (y > x) return SomeFunction(x, y - x);
}
The value returned by SomeFunction(15, 255) is ____________.
Show answer without attempting

Answer: 15

Q49

GATE CS 2021 CS-2RecursionNAT2 marks
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 without attempting

Answer: 60

0/20 correct0 marks