Doubt in my code

Hello, here is the code :

It is not giving me the required output. What is the problem in my code ?

It is giving me the correct output in case when I input for a square matrix. But I am not getting the correct output in case of rectangular matrix. Please help!

Ok the issue is resolved.