Ask Question
23 December, 14:43

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.

+4
Answers (1)
  1. 23 December, 18:37
    0
    The code to this question as follows:

    Code:

    if (x < y) / /if block that check value of x less then value of y

    {

    if (x
    {

    min = x; / /assign value of x in min variable

    }

    else / / inner else block when condition is false

    {

    min = z; / /assign value of z in min variable

    }

    }

    else / /outer else block

    {

    if (y
    {

    min = y; / /assign value of y in min variable

    }

    else / /else block

    {

    min = z; / /assign value of z in min variable

    }

    }

    Explanation:

    In the given question it is defined, that an integer variable " x, y, z, and min" is declared, in which variable "x, y, and z" value is defined, and the variable is used to assign a big value.

    To check the biggest value we use the if-else statement in which, and if block check value of x is less than then the value of y if this condition is true so, inside this another if block declares, that will check if the value of x is less then z. if this is true, it will assign the value of x in min variable else it will assign the value of z in min. In the outer else part, another conditional block has used, that checks if the value of y is less than then the value of z if it is true, it assigns the value of y in min else it will assign the value of z in min.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “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. ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers