Question

**C++** Given three function parameters p1, p2, p3, rotate the values to the right. Rotate means...

**C++**

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 Declare the function's three parameters as reference type. Function return type is void. Use a tmp variable in the function (similar to when swapping two variables). Your first assignment statement in the function should be assigning tmp with one of the three parameter's value. Be careful not to overwrite a value that you expect to use. The order in which you do the assignments matters.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>

using namespace std;

void RotateRight3(int &n1, int &n2, int &n3) {
    int tmp = n3;
    n3 = n2;
    n2 = n1;
    n1 = tmp;
}

int main() {
    int n1, n2, n3;

    cin >> n1;
    cin >> n2;
    cin >> n3;

    RotateRight3(n1, n2, n3);

    cout << n1 << " " << n2 << " " << n3 << endl;

    return 0;
}

Add a comment
Know the answer?
Add Answer to:
**C++** Given three function parameters p1, p2, p3, rotate the values to the right. Rotate means...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT