219k views
0 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 Zong
by
5.2k points

2 Answers

6 votes

Answer:

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

int = tmp;

tmp = p3;

p3 = p2;

p2 = p1;

p1 = tmp;

}

User Del Pedro
by
5.0k points
3 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 Kinzleb
by
5.3k points