155k views
2 votes
11.17 LAB: Max magnitude

Write a function max_magnitude() with three integer parameters that returns the largest magnitude value. Use the function in the main program that takes three integer inputs and outputs the largest magnitude value.

Ex: If the inputs are:

User Victorx
by
8.0k points

1 Answer

2 votes

Final answer:

The task is to create a function called max_magnitude() that identifies the largest magnitude among three integers. The function compares the absolute values and the complete solution, as shown, demonstrates the function and its usage with user-input integers.

Step-by-step explanation:

The question is asking to write a function named max_magnitude() which takes three integer parameters and returns the one with the largest magnitude (i.e., the most distant from zero). To solve this problem, you would typically compare the absolute values of the input integers and return the one with the highest absolute value.

Here's an example in Python:

def max_magnitude(x, y, z):
return max(abs(x), abs(y), abs(z))

# Main program
def main():
a = int(input())
b = int(input())
c = int(input())
print("The largest magnitude is:", max_magnitude(a, b, c))

main()

This code defines a max_magnitude() function then takes three integers from the user, calls the function, and prints out the result.

User Piks
by
8.4k points