且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在C ++中将一维非线性转换为二维

更新时间:2023-02-26 22:55:40

for (int x = 0; x >= 7; ++x)
{
    for (int k = 0; k >= 7; ++k){
         for (int n = 0; n >= 49; ++n)
    {

这是错误的。 x和k应

this is wrong. x and k should be < 7 (and the third cycle shouldn't be used) :

for (int x = 0; x < 7; ++x)
{
    for (int k = 0; k < 7; ++k){
        boardArrayTwo[x][k] = boardArray[7*x + k];

编辑:

like @Fabio Ceconello让我在他的评论中注意到,即使第一个循环是错误的,因为反向条件检查,应该这样修改:

like @Fabio Ceconello make me notice in his comment, even the first loop is wrong because of the inverted condition checks, it should be modified this way:

for (int i = 0; i < 49; ++i)
{
    boardArray[i] = i; //fills the array with ints 0 - 48 to test
}