Source Code :
#include<iostream.h>
class var {
public:
void swap(int &a,int &b) {
a=a+b;
b=a-b;
a=a-b;
cout<<endl<<"After swapping : ";
cout<<endl<<"Value of 'a' :"<<a;
cout<<endl<<"Value of 'b' :"<<b;
}
int main() {
int a,b;
var ob1;
cout<<"Value of 'a' :";
cin>>a;
cout<<"Value of 'b' :";
cin>>b;
ob1.swap(a,b);
return 0;
}
Output :
Value of ‘a’ : 23
Value of ‘b’ : 45
After swapping :
Value of ‘a’ : 45
Value of ‘b’ : 23
No comments:
Post a Comment