Swapping Without Temporary variable C++
Swap Two No without using any temporary variable
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b;
cout<<"\n\n--------Program To Swap Two Numbers without Temprary veriale-------\n\n";
cout<<"\n\nEnter First No: ";
cin>>a;
cout<<"\n\nEnter Secont No: ";
cin>>b;
cout<<"\n\nA= "<<a<<" B= "<<b;
cout<<"\n\n----------Swap-------------\n\n";
a=a+b;
b=a-b;
a=a-b;
cout<<"\n\nA= "<<a<<" B= "<<b;
getch();
}
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b;
cout<<"\n\n--------Program To Swap Two Numbers without Temprary veriale-------\n\n";
cout<<"\n\nEnter First No: ";
cin>>a;
cout<<"\n\nEnter Secont No: ";
cin>>b;
cout<<"\n\nA= "<<a<<" B= "<<b;
cout<<"\n\n----------Swap-------------\n\n";
a=a+b;
b=a-b;
a=a-b;
cout<<"\n\nA= "<<a<<" B= "<<b;
getch();
}
Post a Comment