Exchange two numbers (c)
Exchange two numbers of contents. 1.1 create temporary variables (1) create variables and use # include <stdio. h> int main () {int a = 10; int B = 20; int t; t = a; a = B; B = t; printf ("a = % d, B = % d \ n ", a, B); return 0 ;}( 2) create a temporary variable, function call # include <stdio. h> void swap (int * a, int * B); int main () {int a = 10; int B = 20; swap (& a, & B ); // function call printf ("a = % d, B = % d \ n", a, B); return 0;} void swap (int * a, int * B) {int temp; temp = * a; * a = * B; * B = temp;} 1.2 do not need to create a temporary variable (1) exclusive or # include <stdio. h> int main () {int a = 5; // 0101int B = 3; // 0011a = a ^ B; // 0110b = a ^ B; // 0101a = a ^ B; // 0011 printf ("a = % d \ nb = % d \ n", a, B); return 0 ;}( 2) addition and subtraction # include <stdio. h> int main () {int a = 10; int B = 20; a = a + B; B = a-B; a = a-B; printf ("a = % d \ nb = % d \ n", a, B); return 0;} Note: Generally, addition and subtraction are not required, and overflow may occur.