As I have understood the result array should look as
1 2 3
4 5 6
7 8 9
should not it?
There are many ways to do this. For example to use standard algorithm std::iota. But if you want to use loops yourself then you can do this for example the following way
1 2 3 4
for ( int i = 0; i < 3; i++ )
{
for ( int j = 0; j < 3; j++ ) grid[i][j] = 3 * i + j + 1;
}
or
1 2 3 4
for ( int i = 0, value = 0; i < 3; i++ )
{
for ( int j = 0; j < 3; j++ ) grid[i][j] = ++value;
}