Saturday, February 23, 2013

C++ Code Of Swap Value without Third Variable



Write a program to swap value of two variables without using third variable


#include<iostream.h>
#include<conio.h>

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;

	getch();
	return 0;
}

No comments:

Post a Comment