C++ Program to Swap Two Numbers Without Using Third(Temporary) Variable
In this program we will swap two numbers without using a third variable.
- //C++ Program to swap two numbers without using third(temporary) variable
-
- #include <iostream>
- using namespace std;
-
- int main()
- {
- int a, b;
- cout<<"Enter first number: ";
- cin>>a;
-
- cout<<"Enter second number: ";
- cin>>b;
-
- a = a + b;
- b = a - b;
- a = a - b;
-
- cout<<"Swapping of the numbers are= "<<a<<" and "<<b;
- return 0;
- }
Output

Solution not working or have any suggestions? Please send an email to [email protected]
Download Android App