Ask Question

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.

+3
Answers (1)
  1. 17 April, 09:26
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers