Write a function max_magnitude() with two integer input parameters that returns the largest magnitude value. Use the function in a program that takes two integer inputs, and outputs the largest magnitude value.Ex: If the inputs are:

5 7

the function returns:


Ex: If the inputs are:

-8 -2

the function returns:


Note: The function does not just return the largest value, which for -8 -2 would be -2. Though not necessary, you may use the absolute-value built-in math function.

Your program must define and call a function:

int MaxMagnitude(int userVal1, int userVal2)



using namespace std;

/* Define your function here */

int main() {

/* Type your code here */

return 0;


Ex: If the inputs are: 
5 7 
the function returns:


def max_magnitude(user_val1, user_val2):

if abs(user_val1) > abs(user_val2):

return user_val1


return user_val2

if __name__ == '__main__':

n1 = int(input("Enter the first integer number: "))

n2 = int(input("Enter the second integer number: "))

print("The largest magnitude value of", n1, "and", n2, "is", max_magnitude(n1, n2))


Rate answer
Wrong answer?

If your question is not fully disclosed, then try using the search on the site and find other answers on the subject Computers and Technology.

Find another answers

Load image