Swap rows i and r Divide row r by M[r, lead] for 0 ≤ j < rowCount do if j ≠ r do Subtract M[j, lead] multiplied by row r from row j end if end for lead = lead + 1 end for end function The following pseudocode converts the matrix to a row echelon form (not reduced): function ToRowEchelonForm(Matrix M) is nr := number of rows in M nc := number of columns in M for 0 ≤ r < nr do allZeros := true for 0 ≤ c < nc do if M[r, c] != 0 then allZeros := false exit for end if end for if allZeros = true then In M, swap row r with row nr nr := nr - 1 end if end for p := 0 while p < nr and p < nc do label nextPivot: r := 1 while M[p, p] = 0 do if (p + r) <= nr then p := p + 1 goto nextPivot end if In M, swap row p with row (p + r) r := r + 1 end while for 1 ≤ r < (nr - p) do if M[p + r, p] != 0 then x := -M[p + r, p] / M[p, p] for p ≤ c < nc do M[p + r, c] := M[p , c] * x + M[p + r, c] end for end if end for p := p + 1 end while end function Notes References . . External links Interactive Row Echelon Form with rational output Numerical linear algebra Articles with example pseudocode de:Lineares Gleichungssystem#Stufenform, Treppenform