77.0k views
2 votes
Given the integer variables x, y, and z, write a fragment of code that assigns the smallest of x, y, and z to another integer variable min.Assume that all the variables have already been declared and that x, y, and z have been assigned values).

User Parasietje
by
5.3k points

1 Answer

3 votes

Answer:

x <= y ? ((x <= z)? min = x: min = z):((y<=z)? min = y : min = z);

Step-by-step explanation:

The above written code segment assigns the minimum value from x,y and z to the variable min.For doing this I have used conditional operator to find the minimum of these three variables x,y and z and assigns the value of the minimum variable to the variable min.

User Kotaro
by
5.1k points