GATE CS 2021 Set 2 | Question 33

Programming & Data Structures › Functions · NAT · 1 mark · Answer: 15

  1. Question 33Programming & Data Structuresnat1 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 ______.

    Answer: 15

    Solution

    The function performs the subtractive Euclidean algorithm, returning (with 1 as the base case). .

More GATE PYQ on Functions

All GATE CS Programming & Data Structures PYQ →

Attempt GATE CS 2021 Set 2 in real GATE exam mode

Full paper with a timer, the GATE interface and a topic-wise analysis — free.

Create free account →