Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How to exchange the values of three integers ABC in C language?
How to exchange the values of three integers ABC in C language?
The exchange of two variable values generally needs the help of an auxiliary variable.

int a=3,b=4,t;

The values of a and b can be exchanged by the following three statements (this operation is a bit like exchanging the liquid in two bottles with an empty bottle):

t = a; a = b; b = t;

I don't know what "the exchange of values between ABCs" is. If we want to "rotate" A = 1, B = 2 and C = 3 into A = 2, B = 3 and C = 1,

Then use the following statement to achieve:

t = a; a = b; b = c; c = t;

If you want to change three variables of arbitrary size into a sequence from small to large through exchange, you can use the following program segment:

int a,b,c,t;

Scanf("%d %d %d ",& i, & ampb & amp;; c);

If (a & gtb){ t = a;; a = b; b = t; }

If (a & gtc){ t = a;; a = c; c = t; }

If (b & gtc){ t = b;; b = c; c = t; }

Printf ("The order from small to large is: %d %d %d\n", a, b, c);