A program to get 2 values inputted by the user in variables a and b, then swap these values (i.e. the values of variables a & b should interchange) without using a third variable.

 

#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();
double a,b;
cout<<"a= ";
cin>>a;
cout<<"b= ";
cin>>b;
a=a+b;
b=a-b;
a=a-b;
cout<<"The swapped values are:"<<endl;
cout<<"a= "<<a<<endl;
cout<<"b= "<<b;
gotoxy(25,24); cout<<"Press any key to continue......";
getch();
}

 

 

< Back