C++ Program to Swap Two Numbers

description: This is C++ program to swap two number using temporary variables 
code:
#include <iostream>
using namespace std;

int main()
{
    int x = 10, y = 20, temp;
    cout<<"Enter the value of x :";
    cin>>x;
    cout<<endl<<"Enter the value of y:";
    cin>>y;

    cout << "Before swapping variable" << endl;
    cout << "value of x = " << x <<endl;
    cout << " value of y = " << y << endl;

    temp = x;
    x = y;
    y = temp;

    cout << "\nAfter swapping variable." << endl;
    cout << "value of x = " <<x <<endl;
    cout << "value of y = " << y << endl;

    return 0;
}
output:

Enter the value of x : 30

Enter the value of y : 60
Before swapping variable.
value of x = 30
value of y = 60

After swapping variable.
value of x = 60
value of y = 30

description: This is C++ program to swap two number without temporary variables 
code:
#include <iostream>
using namespace std;

int main()
{
    int x = 10, y = 20, temp;
    cout<<"Enter the value of x :";
    cin>>x;
    cout<<endl<<"Enter the value of y:";
    cin>>y;

    cout << "Before swapping variable" << endl;
    cout << "value of x = " << x <<endl;
    cout << " and value of y = " << y << endl;

    temp = x;
    x = y;
    y = temp;

    cout << "\nAfter swapping variable." << endl;
    cout << "value of x = " <<x <<endl;
    cout << "value of y = " << y << endl;

    return 0;
}
output:
Enter the value of x :10

Enter the value of y:20
Before swapping variable
value of x = 10
value of y = 20

After swapping variable.
value of x = 20
value of y = 10

LANGUAGE