#include <stdio.h> #include <math.h> int main(void) { int a, b, t; scanf("%d%d", &a, &b); /* 方法一:三变量法 t = a; a = b; b = t; 方法二: a = a - b; b = a + b; a = b - a; 方法二变种: a = a + b; b = a - b; a = a - b; */ //方法三:异或运算,原因是对于整形变量a,有a^a=0 a = a ^ b; b = a ^ b; a = a ^ b; printf("%d %d\n", a, b); return 0; }
时间: 2024-10-23 21:21:46