#include <stdio.h> int main(int argc, const char * argv[]) { int a = 3, b = 4; printf("a = %d, b = %d\n", a, b); /* 1.加减法 a = b - a; b = b - a; // b - (b - a) = a a = b + a; // a + b - a = b printf("a = %d, b = %d\n", a, b);*/ // 2.按位异或 a = a^b; b = a^b; // a ^ b ^ b = a a = a^b; // a ^ b ^ a = a ^ a ^ b = b printf("a = %d, b = %d\n", a, b); return 0; }
效果图:
时间: 2024-09-28 17:12:45