易百教程

写一个不使用第三个变量程序来交换两个数字?

参考下面实现代码:

#include<stdio.h>      
#include<conio.h>      
main()      
{      
    int a=10, b=20;    //declaration of variables.  
    clrscr();        //It clears the screen.  
    printf("Before swap a=%d b=%d",a,b);        

    a=a+b;//a=30 (10+20)       
    b=a-b;//b=10 (30-20)      
    a=a-b;//a=20 (30-10)      

    printf("After swap a=%d b=%d",a,b);      
    getch();      
}