517,229 views
24 votes
24 votes
Given three function parameters p1, p2, p3, rotate the values to the right. Rotate means to shift each item to the item on the right, with the rightmost item rotating around to become the leftmost item. If initial values are 2 4 6, final values are 6 2 4. Hints:

Required:
Declare the function's three parameters as reference type. Function return type is void.

User Zartog
by
2.9k points

2 Answers

13 votes
13 votes

Answer:

void RotateRight3( int& p1, int& p2, int& p3) {

int = tmp;

tmp = p3;

p3 = p2;

p2 = p1;

p1 = tmp;

}

User Enzi
by
2.8k points
18 votes
18 votes

Answer:

#include <iostream>

using namespace std;

void RotateRight3( int& p1, int& p2, int& p3) {

int = tmp;

tmp = p3;

p3 = p2;

p2 = p1;

p1 = tmp;

}

int main() {

int n1, n2, n3;

cin >> n1;

cin >> n2;

cin >> n3;

RotateRight3(n1, n2, n3);

cout << n1 << " " << n2 << " " << n3 << end1;

return 0;

}

User Dharanidharan
by
3.5k points