edited by
17,215 views
57 57 votes

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

3 Answers

Best answer
113 113 votes
$$\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}$$
Answer D.
edited by
14 14 votes
$Trial (a,b,c)$ return the median element of the $\text{a , b and c}$ , but not middle element of $\text{a , b and c}$ , so answer is $(D).$
edited by
6 6 votes
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
Answer:
Position:
Show:

Related questions

43 43 votes
6 answers 6 answers
16.7k
16.7k views
Kathleen asked Sep 23, 2014
16,702 views
The number of binary strings of $n$ zeros and $k$ ones in which no two ones are adjacent is$^{n-1}C_k$$^nC_k$$^nC_{k+1}$None of the above
72 72 votes
8 answers 8 answers
26.5k
26.5k views
Kathleen asked Sep 23, 2014
26,522 views
If $T_1 = O(1)$, give the correct matching for the following pairs:$$\begin{array}{|ll|ll|}\hline & \text{(M) $T_n = T_{n-1} + n$} & \text{(U) $T_n = O(n)$} \\\hline & ...
48 48 votes
5 answers 5 answers
24.9k
24.9k views
Keith Kr asked Sep 12, 2014
24,938 views
The minimum number of record movements required to merge five files A (with $10$ records), B (with $20$ records), C (with $15$ records), D (with $5$ records) and E (with ...
50 50 votes
3 answers 3 answers
10.2k
10.2k views
Kathleen asked Sep 23, 2014
10,202 views
Consider the following algorithms. Assume, procedure $A$ and procedure $B$ take $O (1)$ and $O(1/n)$ unit of time respectively. Derive the time complexity of the algorith...