Trusted by millions of Kenyans
Study resources on Kenyaplex

Get ready-made curriculum aligned revision materials

Exam papers, notes, holiday assignments and topical questions – all aligned to the Kenyan curriculum.

Create a function in C++ called order() that takes two integer reference parameters. If the first argument is greater than the second argument, reverse the...

Create a function in C++ called order() that takes two integer reference parameters. If the first argument is greater than the second argument, reverse the two arguments. Otherwise, take no action. That is, order the two arguments used to call order() so that, upon return, the first argument will be less than the second. For example, given
int x=1, y=0;
order(x, y);
following the call, x will be 0 and y will be 1.

Answers


Davis

#include
using namespace std;
void order(int &a, int &b)
{
int t;
if(aelse { //swap a and b
t = a;
a = b;
b = t;
}
}
int main()
{
int x=10, y=5;
cout << "x: " << ", y: " << y << "\n";
order(x, y);
cout <<"x: "<< x << ", y: " << y << "\n";
return 0;

Githiari answered the question on June 8, 2018 at 19:29

Answer Attachments

Exams With Marking Schemes

Related Questions