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.
void main()
{
int d,e,f;
printf("\nInput 3 digits to circular shift it(x,y,z)");
scanf("%d%d%d",&d,&e,&f);
circs(&d,&e,&f);
printf("\The shifted values are x=%d, y=%d, z=%d",d,e,f);
}
circs(int *x, int *y, int *z)
{
int a,b,c;
a=*z;
b=*x;
c=*y;
*x=a;
*y=b;
*z=c;
}
Subscribe to:
Post Comments (Atom)
#include
ReplyDelete#include
int main()
{
int a,b,c,temp;
scanf("%d %d %d",&a,&b,&c);
temp=c; //Swap 1st and 3rd
c=a;
a=temp;
temp=b; //Swap 2nd and 3rd
b=c;
c=temp;
printf("\n%d %d %d",a,b,c);
getch();
}
The program requires you to shift the values of a,b,c using a function and not within main() itself.
Deletebhai tu genius hai; yahan kya kar raha hai
Delete