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


Next: Create a function called reverse() that takes two parameters. The first parameter called str, is a pointer to a string that will be reversed upon...
Previous: (a)Unda nomino kutokana na vivumishi vifuatavyo (i)Zuri (ii)Hodari (b)Yakinisha sentensi hii, Asipotoka nje hataona cha mtema kuni

View More Computer Science Questions and Answers | Return to Questions Index


Exams With Marking Schemes

Related Questions