#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
void rotate(int*,int*,int*);
clrscr();
printf("Enter three integers: ");
scanf("%d %d %d",&a,&b,&c);
printf("\n\nVariables as given: a=%d, b=%d, c=%d",a,b,c);
rotate(&a,&b,&c); // Function call by reference
printf("\n\nVariables after 1st rotation: a=%d, b=%d, c=%d",a,b,c);
rotate(&a,&b,&c); // Function call by reference
printf("\n\nVariables after 2nd rotation: a=%d, b=%d, c=%d",a,b,c);
rotate(&a,&b,&c); // Function call by reference
printf("\n\nVariables after 3rd rotation: a=%d, b=%d, c=%d",a,b,c);
}
void rotate(int *a,int *b,int *c)
{
//swap values between 'a' & 'c'
*a = *c^*a;
*c = *c^*a;
*a = *c^*a;
//swap values between 'b' & 'c'
*b = *c^*b;
*c = *c^*b;
*b = *c^*b;
return;
}
<< Previous Answer | Next Answer >> |