#include<iostream.h>
#include<conio.h>
class Swap
{
public:
int a,b;
float x,y;
Swap(int m,int n)
{
a=m;
b=n;
cout<<"\n Before interchange :";
cout<<"\n Value of a : "<<a;
cout<<"\n Value of b : "<<b;
a=a+b;
b=a-b;
a=a-b;
cout<<"\n After interchange :";
cout<<"\n Value of a : "<<a;
cout<<"\n Value of b : "<<b;
}
Swap(float j,float k)
{
x=j;
y=k;
cout<<"\n Before interchange :";
cout<<"\n Value of x : "<<x;
cout<<"\n Value of y : "<<y;
x=x+y;
y=x-y;
x=x-y;
cout<<"\n After interchange :";
cout<<"\n Value of x : "<<x;
cout<<"\n Value of y : "<<y;
}
};
int main()
{
clrscr();
Swap s1(10,20);
Swap s2(3.14f,4.13f);
getch();
return 0;
}
No comments:
Post a Comment