The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
+18 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

asked in Algorithms by Veteran (59.5k points)
edited by | 1.9k views
if ((a>=b) && (c<b))

missing in question.

3 Answers

+39 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 (355k points)
edited by
but sir there is no middle element in 111, so it wont find. what about other cases?
@Aspi this condition must also be handled by the program to guarentee that it returns a middle element for any three inputs.
it is going to infinite loop here.
what a great thinking you have ! Arjun sir
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) option D ,,,is right one
+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 (6k points)
reshown by
For 3 values on sorting them its hould be middle value, but for same input a=b=c its falling into infinite loop
How it is returning median value can you justify using options?
what is the meaning of median of a,b,c here?
+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)Someone says it return median element of a,b and c not middle element of a,b and c . But here middle and median are same.(For those who asking what is median -The median is the number that lies in the middle when all of the data numbers are written in order.) so that statement is wrong. But actually it does not return median or middle element.
3)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
answered by (47 points)
edited by

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

38,079 questions
45,571 answers
49,040 users