Please provide solution in C++: Write a function MaxMagnitude with two input parameters, that returns the largest-magnitude value. If the inputs are 5 7, the function returns 7. 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. Use the function in a program that takes two integer inputs, and outputs the largest-magnitude value. #include using namespace std; int main() { //int MaxMagnitude; int userVal1; int userVal2; { if(abs(userVal1)>abs(userVal2)) return userVal1; else return userVal2; }
Please provide solution in C++:
Write a function MaxMagnitude with two input parameters, that returns the largest-magnitude value. If the inputs are 5 7, the function returns 7. 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.
Use the function in a program that takes two integer inputs, and outputs the largest-magnitude value.
#include <iostream>
using namespace std;
int main() {
//int MaxMagnitude;
int userVal1;
int userVal2;
{
if(abs(userVal1)>abs(userVal2))
return userVal1;
else
return userVal2;
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images