不借助第三个变量,交换两个数

void fun1()
{
    int a = 10, b = 100;

    a = a + b;
    b = a - b;
    a = a - b;
    printf("a = %d b=%d\n", a, b);
}

void fun2()
{
    int a = 10, b = 100;
    a = a * b;
    b = a / b;
    a = a / b;
    printf("%d\n%d\n", a, b);
}

void fun3()

    int a = 10, b=100;
    a ^= b;
    b ^= a;
    a ^= b;
    printf("%d\n%d\n", a, b);

你可能感兴趣的:(不借助第三个变量,交换两个数)