Search code examples
carraysmultidimensional-arrayadjacency-matrix

How to zero specific column of 2d array


Lets say I have a specific 2d array of 100x100 like so

I'm implementing an adjacency matrix and thus I want to be able to zero a specific column and line (the same column and line in this case), zeroing lines is pretty straightforward but I'm not really able to understand how I would go about for columns.

For example to zero the 2nd element of the adjacency matrix:

enter image description here


Solution

  • int column=1; //in your example
    int row=1;//in your example
    
    
    //for rows
    for(int i = 0; i<numberofrows; i++)
    {
      array[i][column]=0;
    }
    
    //for columns
    for(int i = 0; i<numberofcolumns; i++)
    {
      array[row][i]=0;
    }