edited by
11,095 views
47 votes
47 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

edited by

3 Answers

Best answer
85 votes
85 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
9 votes
9 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)
reshown by
2 votes
2 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:

Related questions

35 votes
35 votes
4 answers
2
Keith Kr asked Sep 12, 2014
14,386 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 ...
41 votes
41 votes
3 answers
3
31 votes
31 votes
3 answers
4
Kathleen asked Sep 23, 2014
5,092 views
Let $A$ be an $n \times n$ matrix such that the elements in each row and each column are arranged in ascending order. Draw a decision tree, which finds $1$st, $2$nd and $...