# Write a program to swap two numbers without using third variable.

#include<iostream>
#include<stdlib.h>
using namespace std;
int main()
{
int a,b;
cout<<“Enter The First NO: “;
cin>>a;
cout<<“Enter The 2nd NO: “;
cin>>b;
cout<<“Before Swaping the Values Are: \na=”<<a<<endl<<“b=”<<b <<endl;
//the next three lines for swaping the value
a=a-b;
b=a+b;
a=b-a;
cout<<“After Swaping the Values Are: \na=”<<a<<endl<<“b=”<<b <<endl;
return 0;
system(“Pause”);
}

Explanation of this program:

this is a c++ program in which we are using only two no for swaping the logic is only in 3 steps
a=a-b;
b=a+b;
a=b-a;
first of all we asume that
a=5 and b=10
so now a=a-b; gives a=-5;
then b=a+b; gives b=(-5)+10=5 here we take the value of a -5 because now -5 was stored in variable a.
then a=b-a; gives a=(5)-(-5)=10 so the problem is solved and the values are replaced without using third variable
best of luck…..
#include<stdlib.h> header file is used because we use the function system(“pause”);
this function is used for print your output while you did not enter any key.