title: What algorithm could be used to move from a position across a two-dimensional array
body: <p>Since last night I have been working with two-dimensional array in C and have obtained a random position (x) and (y) in my matrix NxN and I have assigned the value '1' (matrix [x] [y] = 1).</p>
  <p>It turns out that my matrix in all its cells contains the number '0' and several '1'. But there is a '1' generated after the random position (this I have already developed).</p>
  <p><a href="https://i.stack.imgur.com/XSprk.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XSprk.jpg" alt="Initial matrix" /></a></p>
  <p>Then you need some idea or algorithm, for that random starting position to fill all other cells that have '0' in the matrix. I know I must move in 8 directions within the adjacency matrix cell 1 to 1.</p>
  <p><a href="https://i.stack.imgur.com/vUemR.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vUemR.jpg" alt="Directions" /></a></p>
  <p>I have a theory to solve it, but not if it is correct, I explain:</p>
  <p>If my position would be random (x, y) then the movements to be made are:</p>
  <p>Right (x, y + 1).</p>
  <p>Up (x-1, y)</p>
  <p>Top-Right (x-1, y-1).</p>
  <p>..and so on..</p>
  <p>Assuming that to be right, could go that way this whole matrix and where there is a '0' put '1' ?, but that iterative or recursive algorithm could work for me?</p>
  <p>regards</p>