Ask Question
16 April, 22:37

Given x and y, each associated with an int, write a fragment of code that associates the larger of these with another variable named max.

+3
Answers (1)
  1. 17 April, 02:11
    0
    The program to this question as follows:

    Program:

    x=int (input ('Input the first number: ')) #defining variable x and input value by user

    y=int (input ('Input the second number: ')) #defining variable y and input value by user

    if x > y: #if block to check value x>y

    max=x #define variable max that hold variable x value

    print ('max number is: ', x) #print value

    else: #else block

    max=y #define variable max that holds variable y value

    print ('max number is: ', y) #print value

    Output:

    Input the first number: 22

    Input the second number: 33

    max number is: 33

    Explanation:

    In the above code two-variable, "x and y" is defined, which holds a value, which is input by the variable. In the next step, the if block statement is used that can be described as follows:

    In the if block, it will check x is greater than y it will define a variable, that is "max", that holds variable x value and prints its value. In the else block, if the above condition is false it uses the max variable, that holds variable y value and prints its value.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Given x and y, each associated with an int, write a fragment of code that associates the larger of these with another variable named max. ...” 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