Given three variables x, y, z write a function to circularly shift their values to right. In other words if x = 5, y = 8, z = 10 after circular shift y = 5, z = 8, x =10 after circular shift y = 5, z = 8 and x = 10. Call the function with variables a, b, c to circularly shift values.
#include <stdio.h>
void shift(int* a, int* b, int* c)
{
    int tmp;
    tmp = *c;
    *c = *b;
    *b = *a;
    *a = tmp;
}
int main()
{
    int x, y, z;
    x = 5; y = 8; z = 10;
    printf("Initial values: x=%d, y=%d, z=%d\n", x, y, z);
    shift(&x, &y, &z);
    printf("Shift:          x=%d, y=%d, z=%d\n", x, y, z);
    
    return 0;
}
Comments