"The best way to cheer yourself up is to try to cheer somebody else up." Mark Twain

Thursday, January 7, 2010

swap two integers without a third variable


#include<iostream.h>
#include<conio.h>
void main()
{
int x,y;
cout<<"\n Enter 2 integers respectively:";
cin>>x>>y;


clrscr();


cout<<"\n The original value in x = " << x << " and  y = " << y;


x = x+y;
y = x - y;
x = x - y;


cout<<"\n The swaped value in x = " << x << " and y = " << y;
getch();
}







No comments:

Post a Comment

C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off.
Now Playing: Ballade Pour Adeline

About Me

My photo
I m an IT lecturer of a college. I love social-work. I want to do something beneficial for society before dying , that can promote our society, to some extent.