Ask Question
21 July, 15:48

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.

+2
Answers (1)
  1. 21 July, 16:40
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers