2.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

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

missing in question.

$$\begin{array}{|l|l|l|l|} \hline \textbf{a} & \textbf{b} & \textbf{c} & \textbf{Return} \\\hline \text{1} & \text{1} & \text{1} & \text{The final return statement is c < b.}\\&&&\text{ So, this never returns. } \\\hline \end{array}$$
edited
+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.
+10
it is going to infinite loop here.
+1
what a great thinking you have ! Arjun sir
0
when we will take a=b=c then this program will generate infinite loop (because of b>c condition,to make it finite it should be b>=c)...so option D ,,,is right one
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)
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?
0

If we write a,b, c in a sorted order then the number at the middle position is called Median element.

e.g. we've 3 numbers - 3 ,2 ,4

sorted order - 2 3 4 (3 is median)

1)First of all,in first if statement parenthesis are not balanced .so it  is Syntax error. there is no option called "syntax error".if we forget the balancing parenthesis we can move further.
2)let consider example
Trail(7,2,6) return 6
Trail(5,4,9) return 5
So from example you can conclude that it dose not return maximum or minimum or middle of element. in another case if a=b=c ,it stuck in infinite loop. so answer is d) None of the above
edited by
0
but 6 is the middle of 7,2,6

and 5 is middle of 5,4,9
0
Yes u r right.i forgot "ordering".thank u to inform that
0
If we try it for a=8, b=6, c=4

it is going to produce middle element for all three cases if we can shuffle the values accordingly to check every case.

2