Assuming the input matrix is non-singular, there are many well-proven algorithms for matrix inversion.

To overcome your immediate problem of zeros on the main diagonal, you should read up on pivoting in the context of matrix manipulation. While you're at it, have a look at condition number.

the matrix in the example is non singular and I am using one of the proven algorithms(gauss jordan matrix inversion)

don't know much about pivoting but the usual solution on the internet is to transform the matrix so remove zeros from the diagonal entries but they are not full prove

Like one posted on geeksforgeeks (https://www.geeksforgeeks.org/finding-inverse-of-a-matrix-using-gauss-jordan-method/) cant solve the matrix in the example