problem statement:- swapping of two numbers means you are given two numbers in variables a and b respectively and with the use program you have to swap value of a to b and value of b to a
#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
13 18
before swapping
13 18
after swapping
18 13
#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
13 18
before swapping
13 18
after swapping
18 13
No comments:
Post a Comment