【问题标题】:Printing 9x9 array instead of 10x10 array in C++?在 C++ 中打印 9x9 数组而不是 10x10 数组?
【发布时间】:2015-03-12 11:31:34
【问题描述】:

我是 C++ 新手,正在学习中,请帮助。

我有一个 [10][10] 的二维数组,如下所述。我只能打印出 [1][0] 数组向前,为什么会这样?

const int row = 10;
const int column = 10;

int test2[row][column] = {
        { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
        , { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
        , { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
        , { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
        , { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
        , { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
        , { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
        , { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
        , { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
        , { 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 }
};

然后从这里,我做了一个双循环来画出一些东西。

for (int i = 0; i < row; i++)
        {
            for (int j = 0; j < column; j++)
            {
                if (test2[i][j] == 1)
                {
                    g->DrawRectangle(blackPen, 100, 100, j * 50, i * 50);
                    //Rectangle = x coordinate, y coordinate, width of rectangle, height of rectangle)
                }
                else if (test2[i][j] == 0)
                {
                    g->DrawRectangle(whitePen, i * 50, j * 50, 50, 50);
                }
            }
        }

它不打印第一行,有人可以指导我吗?谢谢。

【问题讨论】:

    标签: c++ arrays printing draw rectangles


    【解决方案1】:

    第一次通过每个for循环j和i都是0,意味着矩形的宽度和高度将为0(i * 50 = 0 * 50 = 0)

    【讨论】:

    • 谢谢!我太糊涂了:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-23
    • 1970-01-01
    • 2021-05-23
    • 1970-01-01
    • 1970-01-01
    • 2021-01-30
    相关资源
    最近更新 更多