打印我的2D数组,Visual Studio Basic

时间:2014-11-12 23:59:44

标签: c visual-studio for-loop multidimensional-array printf

我对编程很陌生,我在切换到学校的VSB C之前使用了c#。我目前正在尝试通过循环打印我的数组,但我得到了一堆无关紧要的数字。关于如何在将来避免这种情况的任何帮助或提示都会很棒。我的代码如下:

int main()
{

    int flightTimesAndLayoverTimes[2][6] =
    {
        (255, 238, 235, 138, 207),
        (80, 46, 689, 53, 0)
    };

    for (int i = 0; i <= 2; i++)
    {


        for (int j = 0; j < 6; j++)
        {
            printf("%c\n", flightTimesAndLayoverTimes[i][j]);
        }
    }
}

1 个答案:

答案 0 :(得分:1)

试试这个:

int flightTimesAndLayoverTimes[2][6] = {{255, 238, 235, 138, 207},
                                        {80, 46, 689, 53, 0}};

for (int i = 0; i < 2; i++)
{
    for (int j = 0; j < 5; j++)
    {
        printf("%i \n", flightTimesAndLayoverTimes[i][j]);
    }
}