Write the definition of a function named rotate4ints that is passed four int variables. The function returns nothing but rotates the values of the four variables: the first variable, gets the value of the last of the four, the second gets the value of the first, the third the value of the second, and the last (fourth) variable gets the value of the third. So, if i, j, k, and m have (respectively) the values 15, 47, 6 and 23, and the invocation rotate4ints(i,j,k,m) is made, then upon return, the values of i, j, k, and m will be 23, 15, 47 and 6 respectively.

LANGUAGE: C++

CHALLENGE:

Write the definition of a function named rotate4ints that is passed four int variables. The function returns nothing but rotates the values of the four variables: the first variable, gets the value of the last of the four, the second gets the value of the first, the third the value of the second, and the last (fourth) variable gets the value of the third. So, if i, j, k, and m have (respectively) the values 15, 47, 6 and 23, and the invocation rotate4ints(i,j,k,m) is made, then upon return, the values of i, j, k, and m will be 23, 15, 47 and 6 respectively.

SOLUTION:

void rotate4ints( int &i, int &j, int &k, int &m ){
int tmp = m;
m = k;
k = j;
j = i;
i = tmp;
}