//Write a program that does a 3-way swap.
//The function threeWaySwap(a,b,c), will put the value of a in b, b in c, and c in a.
//Without using extra variable
#include <stdio.h>
void threeWaySwap(int *a,int *b,int *c);
void swapTwo(int *x, int *y);
int main ()
{
int a=1,b=2,c=3;
threeWaySwap(&a,&b,&c);
printf("a = %d, b = %d, c = %d" , a,b,c);
return 0;
}
void threeWaySwap(int *a,int *b,int *c)
{
swapTwo(a,b);
swapTwo(a,c);
}
void swapTwo(int *x, int *y)
{
*x=*x+*y;
*y=*x-*y;
*x=*x-*y;
}