In: Computer Science
Code:
#include <iostream>
using namespace std;
void getinput(int &a,int &b,int &c){
//get value of a,b,c from user
cout<<"Enter value of a : ";
cin>>a;
cout<<"Enter value of b : ";
cin>>b;
cout<<"Enter value of c : ";
cin>>c;
}
void swap(int &a,int &b,int &c)
{
// Store sum of all in a
a = a + b + c;
// After this, b has value of a
b = a - (b+c);
// After this, c has value of b
c = a - (b+c);
// After this, a has value of c
a = a - (b+c);
}
int main() {
int a,b,c;
getinput(a,b,c);
swap(a,b,c);
//after swaping three variable
printf("\n---After swap function called---\n\n");
//print variable
printf("Value of a : %d\n",a);
printf("Value of b : %d\n",b);
printf("Value of c : %d\n",c);
}
Output: