You are on page 1of 1

Write a program to swap to numbers without third variable.

#include<iostream>
usingnamespacestd;

intmain()
{
    int a, b;
    cin>> a >> b;

    cout<<"The value of a before swap: "<< a <<endl;


    cout<<"The value of b before swap: "<< b <<endl;
    a = a + b;
    b = a - b;
    a = a - b;
    cout<<"The value of a after swap: "<< a <<endl;
    cout<<"The value of b after swap: "<< b <<endl;
    return0;
}

Output:

You might also like