in Programming in C edited by
12,469 views
26 votes
26 votes

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)$$

  1. $x=3, y=4, z=2$
  2. $x=6, y=5, z=3$
  3. $x=6, y=3, z=5$
  4. $x=5, y=4, z=5$
in Programming in C edited by
12.5k views

4 Comments

Expression includes only comparison operator $>$, a will take value from x,y,z. That's why option B) and C) can be eliminated.

Check for option A) and D).... option A) satisfy
0
0

@Ahwan link is not working.

0
0

Option A: 4

Option B: 6

Option C: 6

Option D: 5

1
1

3 Answers

29 votes
29 votes
Best answer

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$

edited by

4 Comments

Yes , correct @sachin
0
0

convert to if-else

if(x>y)

{ if(x>z) a=x;

   else a=z;

}

else{

 if(y>z) a=y;

  else a=z;

}

option:- 

x y z a
3 4 2 4
6 5 3 6
6 3 5 6
5 4 5 5

 

2
2
thanks
0
0
1 vote
1 vote

If we look at the options carefully,

Only Y has the value  , That means we will only go for the expression that results Y (i.e 3rd one)
To execute expression-3, expression-1 has to be false.
For this x<y  , so option A will be true(i.e 3<4)
0 votes
0 votes

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)

Answer:

Related questions