Answer:
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<iostream>
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: "<<x<<endl;
cout<<"The minimum of two numbers is: "<<y<<endl;
}
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;
}
}
Step-by-step explanation:
The program shows how the method is working and the output is