Doubt : Didnot understand why the previous solution didnot work

As in the case when m=3 and n=5, as soon as we print the last row(row=3), startrow=endrow and startcol increments by 1. Now when while loop is checked , it returns true as startrow=endrow and the middle row gets printed. As soon as middle row prints then startrow increments by 1. Now while loop is checked again . This returns false and we come out of loop.