106k views
1 vote
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)

A. x = 6, y =3, z =5
B. x = 6, y = 5, z = 3
C. x = 5, y = 4, z =5
D. x = 3, y =- 4, z = 2

User Kiffin
by
7.7k points

1 Answer

4 votes

The only combination that makes variable 'a' equal to 4 is x = 6, y = 3, z = 5. Option A is the right choice.

Let's evaluate the expression for each combination of x, y, and z:

A. x = 6, y = 3, z = 5

(x > y) = true

((x > z) ? x : z) = (6 > 5) ? 6 : 5 = 6

a = 6

B. x = 6, y = 5, z = 3

(x > y) = false

((y > z) ? y : z) = (5 > 3) ? 5 : 3 = 5

a = 5

C. x = 5, y = 4, z = 5

(x > y) = true

((x > z) ? x : z) = (5 > 5) ? 5 : 5 = 5

a = 5

D. x = 3, y = -4, z = 2

(x > y) = true

((x > z) ? x : z) = (3 > 2) ? 3 : 2 = 3

a = 3

Therefore, the only combination of x, y, and z that makes the variable a get the value 4 in the expression is x = 6, y = 3, z = 5. Option A is the right choice.

User Srekel
by
7.8k points