How To Swap Two Variables Without Using Third Variable


  1. #include<stdio.h>    
  2. void main()    
  3. {    
  4.     Clrscr();    
  5. {    
  6.     int a=5,b=10;    
  7. //process one    
  8.     a=b+a;    
  9.     b=a-b;    
  10.     a=a-b;    
  11.     printf("a= %d  b=  %d",a,b);    
  12.     
  13. //process two    
  14.     a=5;    
  15.     b=10;    
  16.     a=a+b-(b=a);    
  17.     printf("\na= %d  b=  %d",a,b);    
  18. }    
  19.    getch();