C++ Program to Swap Two Numbers



To swap two numbers we will use another temporary variable to store the value of first number.



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

Output


Output!