C语言中定义一个函数交换两个数的值?

2024-12-28 14:21:47
推荐回答(2个)
回答1:

#include

void Swap1(int* a, int* b)

{

    int c = *a;

    *a = *b;

    *b = c;

}


main()

{

    int a, b;

    scanf("%d,%d", &a, &b);

    printf("\na=%d,b=%d", a, b);

    Swap1(&a, &b);

    printf("\na=%d,b=%d", a, b);

}

回答2:

#include void Swap1(int* a, int* b){ int c = *a; *a = *b; *b = c;}
main(){ int a, b; scanf("%d,%d", &a, &b); printf("\na=%d,b=%d", a, b); Swap1(&a, &b); printf("\na=%d,b=%d", a, b);}