logo CodeStepByStep logo

gridMystery

Language/Type: C++ Grid collections

What is the grid state after the following code?

Grid<int> g(4, 3);
for (int r = 0; r < g.numRows(); r++) {       // {{1, 2, 3},
    for (int c = 0; c < g.numCols(); c++) {   //  {1, 2, 3},
        g[r][c] = c + 1;                      //  {1, 2, 3},
    }                                         //  {1, 2, 3}}
}

for (int c = 0; c < g.numCols(); c++) {
    for (int r = 1; r < g.numRows(); r++) {
        g[r][c] += g[r - 1][c];
    }
}
output
(order shuffled)

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.