Swapping Numbers without 3rd Variable

Ram Pothuraju


This is a simple  Program for Swapping of Variable without 3rd Variable. 
 It is also usually asked in Interviews. 








Swapping of Variable without 3rd Variable

#include <stdio.h>
#include <iostream.h>
int main()
{
int a=11;
int b=20;
b=(a+b);                 // a = 11      b=31
a=(b-a);                  // a = 20      b=31
b=(b-a);                 //  a = 20      b=11
printf("%d %d",a,b);
return 0;
}

Tags

Post a Comment

0Comments

Post a Comment (0)