Answer to Question #185866 in C for Muhammad Haris

Question #185866

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. 


1
Expert's answer
2021-04-26T14:37:55-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS