假设我有一个4 * 4矩阵,我提示进入某个位置,那个位置是4,1
(向上移动)现在我想迭代位置(3,1) - (2,1) - (1,1),检查这些值,有时我必须更改这些值,最后打印一个带有更新的新矩阵价值
同样如果有人进入4,4(左移)位置,如何迭代(4,3),(3,3)(2,3),(1,3)
我试过了,到目前为止......
for(rowCount = 0; rowCount < rows; rowCount++) {
for(columnCount = 0; columnCount < columns; columnCount++){
if(rowCount == specialRow && columnCount == specialColumn)
{
if(board[rowCount][columnCount] = 1 )
{
printf("%d \t",board[rowCount][columnCount]);
board[rowCount][columnCount] = 0 ;
}
}
for(rowCount = 0; rowCount < rows; rowCount++) {
for(columnCount = 0; columnCount < columns; columnCount++)
printf("%d \t",board[rowCount][columnCount]);
printf("\n");
}
}
}
答案 0 :(得分:1)
首先根据某些条件更新阵列,让我们说输入是4 4所以你应该这样做
for(rowCount = 0; rowCount < rows; rowCount++) {
for(columnCount = 0; columnCount < columns; columnCount++){
if(columnCount == (specialColumn-1))
{
if(board[rowCount][columnCount] == 1 )
{
printf("%d \t",board[rowCount][columnCount]);
board[rowCount][columnCount] = 0 ;
}
}
}
}
现在假设对矩阵进行了必要的修改,将它们单独打印出来
for(rowCount = 0; rowCount < rows; rowCount++) {
for(columnCount = 0; columnCount < columns; columnCount++)
printf("%d \t",board[rowCount][columnCount]);
printf("\n");
}