//Program to swap two variables without using the third variable.
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b;
cout<<"Enter the value of a & b:"<<endl;
cin>>a>>b;
a=a-b;
b=a+b;
a=b-a;
cout<<"Value of a & b after swapping"<<endl<<"a="<<a<<endl<<"b="<<b;
getch();
}
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b;
cout<<"Enter the value of a & b:"<<endl;
cin>>a>>b;
a=a-b;
b=a+b;
a=b-a;
cout<<"Value of a & b after swapping"<<endl<<"a="<<a<<endl<<"b="<<b;
getch();
}
No comments:
Post a Comment