📌  相关文章
📜  使用第三个变量交换 - C 编程语言代码示例

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

代码示例2
//The code for a function to Swap two number with a temporary variable is as follows
#include

void swapping(int, int);  //function declaration
int main()
{
    int a, b;

    printf("Enter values for a and b respectively: \n");
    scanf("%d %d",&a,&b);

    printf("The values of a and b BEFORE swapping are a = %d & b = %d \n", a, b);

    swapping(a, b);      //function call
    return 0;
}

void swapping(int x, int y)   //function definition
{
    int third;
    third = x;
    x    = y;
    y    = third;

    printf("The values of a and b AFTER swapping are a = %d & b = %d \n", x, y);
}