Which combination of the integer variables $x, y,$ and $z$ makes the variable $a$ get the value $4$ in the following expression?
$$a=(x > y)?((x > z) ?x:z): ((y > z) ?y:z)$$
@Ahwan link is not working.
Option A: 4
Option B: 6
Option C: 6
Option D: 5
Using option (A) : $x=3, y=4, z=2$
$a=(3>4)?$ No
therefore don't evaluate the first part and check second part $((y>z)?y:z)$
$(4>2)?$ Yes
$a=$ value of $y =4$
Answer is (A) $x=3, y=4, z=2$
convert to if-else
if(x>y)
{ if(x>z) a=x;
else a=z;
}
else{
if(y>z) a=y;
option:-
The given expression actually finds the max. of 3 integers. Therefore, the correct option is the one with 4 as the max value. Therefore, correct opt: (A)
64.3k questions
77.9k answers
244k comments
80.0k users