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. }

download android app

Popular C++ Examples


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