logo CodeStepByStep logo

gridMystery

Language/Type: C++ Grid collections
Author: Marty Stepp (on 2016/06/16)

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

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.

© Marty Stepp, all rights reserved.