Showing posts with label Swapping Values of two variables without 3rd variable... Show all posts
Showing posts with label Swapping Values of two variables without 3rd variable... Show all posts

Friday, March 16, 2012

Swapping Values of two variables without 3rd variable..


#include<iostream.h>
#include<conio.h>
void swap(int a,int b);
void main()
{
clrscr();
int x,y;
cout<<"Enter the 1st number";
cin>>x;
cout<<"Enter the 2nd Number";
cin>>y;
swap(x,y);
getch();
}
void swap(int a,int b)
{
a=a+b;
b=a-b;
a=a-b;
cout<<"\t 1st num="<<a<<"\t 2nd num="<<b;
}