📌  相关文章
📜  在不使用第三个变量的情况下交换 2 个数字 - 无论代码示例

📅  最后修改于: 2022-03-11 15:00:36.941000             🧑  作者: Mango

代码示例6
//Swapping Using Addition and Subtraction(+ & -)
void swapping(int x, int y)
{
    x = x + y;    //1
    y = x - y;    //2
    x = x - y;    //3
    printf("The values of a and b AFTER swapping are a = %d & b = %d \n", x, y);
   
}

//Swapping Using Multiplication and Division(* & /)
void swapping(int x, int y)
{
     x = x * y;   //1
     y = x / y;   //2
     x = x / y;   //3
    printf("The values of a and b AFTER swapping are a = %d & b = %d \n", x, y);
   
}

//Swapping Using Bitwise XOR
void swapping(int x, int y)
{
    x = x ^ y;
    y = x ^ y;
    x = x ^ y;
    printf("The values of a and b AFTER swapping are a = %d & b = %d \n", x, y);
   
}