#include<iostream.h>
class a
{
public:
int a,b,c;
void swap();
};
void a::swap()
{
c=a;a=b;b=c;
cout<<"\n after swapping\n";
cout<<a<<" "<<b;
}
void main()
{
a obj;
cout<<"enter two nos.\n";
cin>>obj.a>>obj.b;
cout<<"before swapping\n";
cout<<obj.a<<" "<<obj.b;
obj.swap();
}
output
enter two nos 5 8
before swapping
5 8
after swapping 5 8
class a
{
public:
int a,b,c;
void swap();
};
void a::swap()
{
c=a;a=b;b=c;
cout<<"\n after swapping\n";
cout<<a<<" "<<b;
}
void main()
{
a obj;
cout<<"enter two nos.\n";
cin>>obj.a>>obj.b;
cout<<"before swapping\n";
cout<<obj.a<<" "<<obj.b;
obj.swap();
}
output
enter two nos 5 8
before swapping
5 8
after swapping 5 8
No comments:
Post a Comment