TheFestFever.com

Our aim is to connect students from campuses all over Delhi by making them aware of all Technical, Cultural, Management fests, workshops, Seminars organized by every college in Delhi.

Join Us Now

Program 18: Write a C++ program to swapping two numbers without using the third variable.

#include<iostream>
using namespace std;

void swap(int &a,int &b)
{
	a+=b;
	b=a-b;
	a-=b;
}

int main()
{
	int a,b;
	cout<<"\nenter two values : ";
	cin>>a>>b;
	swap(a,b);
	cout<<"\nafter swapping : "<<a<<" "<<b;
	return 0;
}



If you have any suggestion or found any error in the above program, then do let us know at [email protected] or just comment below.