Check the diagonal of a specific index

Asked

Viewed 280 times

-1

I wanted to know how to check the diagonal of a particular index, for example, put 1 in all the numbers of the diagonals of row 2, column 2

0 1 0 1

0 0 1 0

0 1 0 1

1 0 0 0

  • 2

    What’s your question? Show what you’ve done ... and don’t mix java with C!

  • As if it were a game of chess, where the lady checks her diagonals if she has any piece that threatens her...

  • 2

    it’s interesting to see the code you already have, because I don’t know if I help with java or with c.

  • I couldn’t even start, everything went wrong, it could be java or C, anyone to give me an idea

  • Before asking a question you need to try to solve the problem and post what you have already achieved.

2 answers

0

If you have a value whose index would be [x][y], then the diagonals will have the indices [x-1][y-1], [x+1][y-1], [x-1][y+1] and [x+1][y+1], put this inside a Try... catch with an Arrayindexoutofboundsexception if it is an Dice that does not exist (for example, if you check a box at the corners, then it will only have 1 or 2 diagonals at the 4)

0

I believe it is just to go through the matrix checking where the row is equal to the column and put 1 in these lines.

  for(i=1;i<=n;i++){
       for(j=1;<=n;j++){
          if( i == j){
               m[i][j] = 1;
           }
    }
   }

I recommend you research a little more here because I believe you have something similar posted here already.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.