C language to implement digital exchange

We can imagine how two glasses of water are exchanged in real life:

Find a third cup, pour the water from the first cup into the third cup, then pour the water from the second cup into the first cup, and finally pour the water from the third cup into the first cup. In this way, the exchange of two glasses of water is achieved

The same is true for number exchange in C language:

To realize the exchange of two numbers, you must define an empty variable. The code is as follows

#include <stdio.h>

int main() 
{
    int a,b,tep;
    scanf("a=%d,b=%d",&a,&b);
    tep=a;//将a赋给空变量
    a=b;//将b赋给a
    b=tep;//将已经被赋值的变量重新赋给b
    printf("a=%d,b=%d",a,b);
    return 0;
}

 Note that "=" is the assignment symbol "==" which means equal to

 It should be noted that the input and output formats must be in accordance with the requirements of the topic.

Guess you like

Origin blog.csdn.net/wangduduniubi/article/details/128553490