Ask Question
6 May, 05:22

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.

+4
Answers (1)
  1. 6 May, 07:04
    0
    The program to this question can be given as:

    Program:

    #include / /define header file

    //#include / /define header file

    #include / /define header file

    int MaxMagnitude (int n1, int n2) / /define function.

    {

    int largest_magnitude_value = 0;

    if (abs (n1) > abs (n2))

    {

    / / largest_magnitude_value

    largest_magnitude_value = n1;

    }

    else

    {

    //largest_magnitude_value

    largest_magnitude_value=n2;

    }

    return largest_magnitude_value; / /return value.

    }

    int main () / /define main function

    {

    int n1, n2, x;

    //define variable.

    printf ("Enter first number : ");

    //message

    scanf ("%d",&n1);

    //input first value from user

    printf ("Enter second number : ");

    //message

    scanf ("%d",&n1);

    //input second value from user

    x=MaxMagnitude (n1, n2);

    //variable holds function return value

    printf ("largest magnitude value is = %d", x);

    //print value.

    return 0;

    }

    Output:

    Enter first number : 5

    Enter second number : 7

    largest magnitude value is = 7

    Explanation:

    The description of the above C program can be given as:

    the above program firstly we define the header file in this we define the "math. h" header file that is a part of the "stdlib. h" that stands for standard library. This file includes math function, memory allocation, process control, and others. Then we define a function that is "MaxMagnitude () " function. The return type of this function is int. I this function we pass two integer values that use the conditional statement to check which value is greater. In if block we use the absolute () function that returns an absolute value that holds in a variable that is "largest_magnitude_value". Then we define the main function. In this, we define 3 integer variable that is n1, n2, and x. In the n1 and n2, we take value form the user and pass the value to the function in calling time and use x variable to print function return value.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a function MaxMagnitude with two input parameters, that returns the largest-magnitude value. If the inputs are 5 7, the function ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers