How can we mathematically and algorithmic-ally convert a $n\times n$ matrix to a upper triangular matrix
It appears from the comments that what OP wants to do is to calculate the determinant of a square matrix by using elementary row operations to bring the matrix to upper triangular form, then multiplying all the diagonal entries.
One needs to know that if you get from matrix $A$ to matrix $B$ by
(1) subtracting any multiple of any row of $A$ from any other row of $A$ then $\det B=\det A$;
(2) by exchanging two rows of $A$ then $\det B=-\det A$.
Now, look for a nonzero entry in the first column of your matrix. If there aren't any, stop: the determinant is zero.
If you do locate a nonzero entry in the first column, swap the row containing that entry with the first row [see (2), above], if necessary, then subtract multiples of the first row from each other row in turn [see (1), above] in such a way as to bring all the other entries in the first column to zero.
Now forget about the first row and column of the matrix, and apply the procedure to the rest of the matrix. Keep doing this until an all-zero column halts the computation or until you run out of matrix. If you run out of matrix, you have created an upper triangular matrix, and you know what to do.
This works better in theory than in practice. In theory, it doesn't matter which choices you make along the way; in practice, it can make a great deal of difference. But, then, if you're really looking for a practical way to calculate a determinant, you just use a program someone else has already written that does it for you.