logo CodeStepByStep logo

vectorMystery1

Language/Type: C++ vector collections STL

Write the final contents when the following function is passed each vector below. Assume that a vector would print in the format {10, 20, 30}.

void vectorMystery1(vector& v) {
    for (int i = 0; i < v.size(); i++) {
        int n = v[i];
        if (n % 10 == 0) {
            v.erase(v.begin() + i);
            v += n;
        }
    }
    cout << v << endl;
}
{1, 20, 3, 40}
{80, 3, 40, 20, 7}
{40, 20, 60, 1, 80, 30}

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.