I am attempting to make a Gaussian Elimination solver for systems of linear equations that contain less than 100 equations. I have roughed out a method for creating and filling in the diagonal of a representing matrix (using row flipping) and the standard solving steps. My method for arranging always produces a filled in diagonal, and my whole program can usually solve small systems of 20*20.
The problem occurs when using the ith column of the ith row to eliminate the ith column of the jth row where the jth column of the ith row proceeds to eliminate the jth column of the jth row.
The following image will help illustrate the problem. https://i.stack.imgur.com/9OARf.png

Are there any sure-fire ways to arrange a matrix for Gaussian Elimination or alternatively for LU factorization?