Using temporary variables is very simple
#include <stdio.h>
int main ()
{
int a = 1, b = 2, c = 0;
printf ("a=");
scanf ("%d", &a);
printf ("b=");
scanf ("%d", &b);
c = A;
A = b;
b = C;
printf ("a=%d,b=%d\n", A, b);
System ("pause");
return 0;
}
At this point, I thought I could do the same without adding temporary variables.
The method of adding and reducing can be used
#include <stdio.h>
int main ()
{
int a = 1, b = 2;
printf ("a=");
scanf ("%d", &a);
printf ("b=");
scanf ("%d", &b);
A = a + B;
b = a A;
A = a-B;
printf ("a=%d,b=%d\n", A, b);
System ("pause");
return 0;
}
And the method of XOR
#include <stdio.h>
int main ()
{
int a = 1, b = 2;
printf ("a=");
scanf ("%d", &a);
printf ("b=");
scanf ("%d", &b);
A = a ^ b;//Building a Collection
b = A ^ b;//take out another number in the collection
A = a ^ b;//take out another number in the collection
printf ("a=%d,b=%d\n", A, b);
System ("pause");
return 0;
}
Exchange two-digit values and two-digit values without using a temporary variable