C++ Program to Swap Two Numbers Without Using Third(Temporary) Variable



In this program we will swap two numbers without using a third variable.



  1. //C++ Program to swap two numbers without using third(temporary) variable
  2. #include <iostream>
  3. using namespace std;
  4. int main()
  5. {
  6. int a, b;
  7. cout<<"Enter first number: ";
  8. cin>>a;
  9. cout<<"Enter second number: ";
  10. cin>>b;
  11. a = a + b;
  12. b = a - b;
  13. a = a - b;
  14. cout<<"Swapping of the numbers are= "<<a<<" and "<<b;
  15. return 0;
  16. }

Output
Output!
download android app

Popular C++ Examples









codesadda.com

Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube