Code Box
---------------------------------------------
/*program to swap two values without using third variable */
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,temp;
clrscr();
cout<<"\nEnter two numbers :";
cout<<"\nEnter first number a= ";
cin>>a;
cout<<"\nEnter second number b= ";
cin>>b;
cout<<"\nValues before swapping a= "<<a<<" & b= "<<b;
a=a+b; //swapping
b=a-b;
a=a-b;
cout<<"\n\nValues after swapping a= "<<a<<" & b= "<<b;
getch();
}
No comments:
Post a Comment