124k views
3 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,So if the value of x is 19 the value of y is 13, and the value of z is 23, then after your code executes, the value of min would be 13.

User Vladislav
by
7.0k points

1 Answer

1 vote

Answer:

int min

if (x<=y) then

min=x

else

min=y

endif

if (min>=z) then

min=z

endif

Step-by-step explanation:

I wrote a simple, generic piece of code that first compares the x and y variables and assigns to min the smallest of the two values, then it compares the min variable to the third value and check if the value stored in min is bigger than z, in that case, it means that z is the smallest of all three and it assigns the value of z into min. I took into consideration the possibility that two or the three numbers be equal, which it will still throw the smallest values of the three.

User EversMcc
by
6.4k points