48.2k views
4 votes
Four integer variables, pos1, pos2, pos3, pos4, have been declared and initialized. write the code necessary to "left rotate" their values: for each variable to get the value of the successive variable, with pos4 getting pos1's value.

User Mdarwin
by
5.6k points

1 Answer

1 vote
The code goes like this
int temp;
temp = pos1; pos1 is assigned to temp.
pos1 = pos2; pos2 is assigned to pos1 and at this point temp is same as temp pos2 = pos3; pos3 is assigned to pos2 and at this point temp is same as temp pos3 = pos4; pos4 is assigned to pos3 and at this point pos4 is same as temp pos4 = temp; pos4 is temp now and cycle rotate making pos4 getting pos1 value.
User Chevdor
by
5.5k points