Assignments » Variable, Operator and Expression » set2 » Solution 1

Write a program to swap the values of two variables without using third variable.



#include<iostream>
using namespace std;

int main()
{
	int a,b;
	cout<<"\nEnter two numbers : ";
	cin>>a>>b;
	a=a+b;
	b=a-b;
	a=a-b;
	cout<<"\nAfter swapping numbers are : ";
	cout<<a<<" "<<b;
	
	
	return 0;
}

Enter two numbers : 78 12
After swapping numbers are : 12 78