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