【发布时间】:2021-11-09 23:53:07
【问题描述】:
我正在尝试重新打印一个二维数组,array[7][3]。我试图从最初的输出中得到它
1 2 3
4 5 6
7 6 8
10 11 12
13 14 15
16 17 18
19 20 21
然后首先在矩阵中输出选定的列,但按行输出,就像你选择第 2 列一样,它会输出这个
*3 6 9
12 15 18
21* 1 4
7 10 13
16 19 2
5 8 11
14 17 20
我正在使用 for 循环,但我不知道如何进行交换部分。我分别将它们声明为三个不同的数组 [7]。我想我正确地将单个数组值设置为相同,但打印让我感到困惑
这是我知道无法正常工作的代码片段
//assign to single dimensional arrays
for (index = 0; index < 7; index ++)
{
pickUp[index] = trickDeck[index][columnNumber];
}
for (index = 0; index < 7; index ++)
{
pickUp2[index] = trickDeck[index][first];
}
for (index = 0; index < 7; index ++)
{
pickUp2[index] = trickDeck[index][second];
}
//reassign back to multidimensional
for (index = 0; index < 7; index ++)
{
for (column = 0; column < COLUMNS; column++)
{
trickDeck[index][column] = pickUp[row];
row++;
}
index++;
}
row = 0 ;
for (index = 0; index < 7; index ++)
{
for (column = 0; column < COLUMNS; column++)
{
trickDeck[index][column] = pickUp2[row];
row++;
}
}
row = 0;
for (index = 0; index < 7; index ++)
{
for (column = 0; column < COLUMNS; column++)
{
trickDeck[index][column] = pickUp3[row];
row++;
}
}
}
【问题讨论】:
-
在示例中,9 来自哪里?这是一个错字,应该是 8?还是原版的 9?
-
你说你只想以不同的顺序打印。这是否意味着实际上不需要重新排列元素,您只需要以不同的顺序打印它们?
-
你能把你的问题说得更清楚吗?很难理解你到底想达到什么目的。
标签: c++ arrays matrix multidimensional-array