Monday, November 14, 2011

Swap Without Third Variable

Wap to take a number from user and to swap them without using third variable


#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b;
cout<<"enter a,b";
cin>>a>>b;
a=a+b;
b=a-b;
a=a-b;
cout<<"a="<<a<<endl;
cout<<"b="<<b;
getch();
}

***************
OUTPUT:
 enter a,b 17
15
a=15
b=17
***************

No comments:

Post a Comment