GATE | GATE CS 1999 | Question 49

Consider the following C function definition.

int Trial (int a, int b, int c)
{
    if ((a >= b) && (c < b) return b;
    else if (a>=b) return Trial(a, c, b);
    else return Trial(b, a, c);
}

The function Trial:
(A) finds the maximum of a, b and c
(B) finds the minimum of a, b and c
(C) finds the middle number of a, b and c
(D) None of the above


Answer: (D)

Explanation: Trial (a,b,c) return the median element of the a, b and c,but not middle element of a , b and c. But if a = b = c, then infinite loop.
So, Option (D) is correct.

Quiz of this Question



My Personal Notes arrow_drop_up


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.