C++ Programming

C++ Program to Swap Two Numbers Without Using Temporary Variable

Swap Two Numbers

Write a Program to Swap Two Numbers without Using Temporary Variable.


  • Start the program
  • Input a, b
  • s=a+b, a=s-a, b=s-b
  • Display a, b
  • End the program

Source Code


using namespace std;

int main() {
    int a,b,s;
    cout<<"Enter two integer numbers:";
    cout<<"\nThe entered numbers are: "<<"a = "<<a<<" b = "<<b;
    cout<<"After swapping, the numbers are: "<<"a = "<<a<<" b = "<<b;


Swap Two Numbers


About Author

Tutsmaster.org provides tutorials related to tech and programmings. We are also setting up a community for the users and students.

You may also like

program to find leap year
C++ Programming

C++ Program to Find Leap Year by Using Function

  • March 3, 2016
Write a program to find if the inputted year is a leap year or not by using the concept of