### help me please, so fast.

I could'nt write a c++ program which is;

Write a function void sort2(int &a, int &b) that swaps the values of a
and b if a is greater than b and otherwise leaves a and b unchanged.
For example,
int u = 2;
int v = 3;
int w = 4;
int x = 1;
sort2(u, v); // u is still 2, v is still 3
sort2(w, x); // w is now 1, x is now 4

also :(

Write a function sort3(int &a, int &b, int &c) that swaps its three
arguments to arrange them in sorted order. For example,
int v = 3;
int w = 4;
int x = 1;
sort3(v, w, x); // v is now 1, w is now 3, x is now 4
Hint: Use sort2 of question 1
Last edited on
 ``123456789`` ``````void sort2(int &a, int &b) { if ( b < a ) { int tmp = a; a = b; b = tmp; } }``````
for sort3 ? :S also ı have to have Function prototype (Declaration) about int u = 2;
int v = 3;
int w = 4;
int x = 1;
sort2(u, v); // u is still 2, v is still 3
sort2(w, x); // w is now 1, x is now 4
Last edited on
 ``123456`` ``````void sort3(int &a, int &b, int &c) { sort2( a, b ); sort2( a, c ); sort2( b, c ); }``````
thanks a lot, I will try
I couldn't write Could you write whole program:S
I also can not write the whole program because I do not know what the program shall do. I think it is your task to write the whole program.
Topic archived. No new replies allowed.