Write a function MaxMagnitude() 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: 7 Ex: If the inputs are: -8 -2 the function returns: -8 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)

Respuesta :

Answer:

The function requires evaluate the largest magnitude (the largest value withou sign), so we need to compare the absolute value of the two inputs number. For that we use the abs() function.

The code is as follows, with the comments after // and in italic font:

#include <iostream>   //module for input/output stream objects

#include <cmath>  //math module

using namespace std;

// follows the function definition  

int MaxMagnitude (int userVal1, int userVal2) {

 int Max=0;    //define output variable Max

 if (abs(userVal1) > abs(userVal2)) {  // compare magnitude

   Max = userVal1;   //if Val1 is larger than val2 Max is Val1

 }

 else {

   Max = userVal2;  //else the max is Val 2

 }

 return Max;  //the value returned for this function

 }

// in main we will use the defined function MaxMagnitude

int main() {

  int one = 0;

 int two = 0;

 cin >> one;  //assignation of the first user input to one  

 cin >> two;   //assignation of the second user input to two  

//we call the function using as input the read values

//and write the return of the function, all at once  

  cout << MaxMagnitude(one, two) << endl;  

  return 0;

}

The function MaxMagnitude() with two integer input parameters that returns the largest magnitude value is as follows:

def MaxMagnitude(x, y):

    list1 = [x, y]

    return max(list1)

print( MaxMagnitude(5, 7))

Code explanation:

The code is written in python.

  • The first line of code, we defined a function named "MaxMagnitude" and it accept two parameters x and y.
  • Then we turn the parameters into a list
  • Then we return the maximum value of the list using the max() function.
  • Finally, we call our function with the necessary parameters 5 and 7.

learn more on function here; https://brainly.com/question/15566254