简体   繁体   English

C删除矩阵中的许多元素?

[英]C remove many elements in matrix?

Let's assume I have a matrix[4][10] that looks like this: 假设我有一个矩阵[4] [10]如下所示:

**********
**********
**********
**********

I want to enter a coordinate and remove everything to the right and below the coordinates. 我想输入一个坐标,并删除坐标右侧和下方的所有内容。

For example, if coordinates are 3, 5 it will look like this: 例如,如果坐标为3、5,则它将如下所示:

**********
**********
****
****

If coordinates are 1, 1 it will look like this: 如果坐标为1、1,则它将如下所示:

(blank)

I have tried to do this with loops, but I only succeed removing everything to the right of the coordinates, not everything below it too: 我尝试使用循环来做到这一点,但是我只成功删除了坐标右边的所有内容,而不是下面的所有内容:

for(x; x <= 4; x++)
{
    for(y; y <= 10; y++)
    {
        matrix[x-1][y-1] = ' ';
    }
}

The problem is that after you complete your first iteration of the outer for loop, the value of y is not updated, so it will still be 11 . 问题在于,完成外部for循环的第一次迭代后,y的值不会更新,因此仍为11

void removeBottomRight( char matrix[4][], int x, int y )
{
    for( int xi = x; xi <= 4; ++xi )
    {
        for( int yi = y; yi <= 10; ++yi )
            matrix[xi-1][yi-1] = ' ';
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM