Ask Question
18 August, 08:43

Write the definition of a function named maxmin that is passed four int arguments. The function returns nothing but stores the larger of the first two arguments in the third argument it receives and the the smaller of the first two arguments in its fourth argument. So, if you invoke maxmin (3,7, x, y), upon return x will have the value 7 and y will have the value 3.

+1
Answers (1)
  1. 18 August, 12:03
    0
    To get the values in x and y, we should use the pass - by - reference method. Where a reference to the actual variable is created in the called function. When we update the value inside the called function, it reflects in the calling function.

    C+ + code:

    #include

    using namespace std;

    void maxmin (int p, int q, int &r, int &s);

    int main ()

    {

    int k, l, x, y;

    cout<<"Enter two integers for k and l: ";

    cin>>k>>l;

    maxmin (k, l, x, y);

    cout<<"The maximum of two numbers is: "<
    cout<<"The minimum of two numbers is: "<
    }

    void maxmin (int p, int q, int &r, int &s)

    { / /r and s holding the address of x and y respectively.

    if (p>q)

    {

    r=p;

    s=q;

    }

    else

    {

    r=q;

    s=p;

    }

    }

    Explanation:

    The program shows how the method is working and the output is
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write the definition of a function named maxmin that is passed four int arguments. The function returns nothing but stores the larger of ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers