top of page
Program 2: Using * and /
Let's see another example to swap two numbers using * and /.

#include <iostream>
using namespace std;
int main()
{
int a=5, b=10;
cout<<"Before swap a= "<<a<<" b= "<<b<<endl;
a=a+b; //a=15 (5+10)
b=a-b; //b=5 (15-10)
a=a-b; //a=10 (15-5)
cout<<"After swap a= "<<a<<" b= "<<b<<endl;
return 0;
}
bottom of page