+18 votes
1.7k views

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 functional Trial:

1. Finds the maximum of $a$, $b$, and $c$

2. Finds the minimum of $a$, $b$, and $c$

3. Finds the middle number of $a$, $b$, $c$

4. None of the above

asked
edited | 1.7k views
0
if ((a>=b) && (c<b))

missing in question.

2 Answers

+36 votes
Best answer
$a$ $b$ $c$ Return
1 1 1 The final return statement is $c < b$, so this never returns. Answer D

answered by Veteran (342k points)
edited by
+1
but sir there is no middle element in 111, so it wont find. what about other cases?
+1
@Aspi this condition must also be handled by the program to guarentee that it returns a middle element for any three inputs.
+6
it is going to infinite loop here.
+4 votes
Trial (a,b,c) return the median element of the a , b and c , but not middle element of a , b and c ,, so answer is (D)
answered by Loyal (5.9k points)
reshown
+3
For 3 values on sorting them its hould be middle value, but for same input a=b=c its falling into infinite loop
0
How it is returning median value can you justify using options?
0
what is the meaning of median of a,b,c here?
Answer:

+20 votes
2 answers
1
+7 votes
2 answers
2
+14 votes
3 answers
3