Just a small correction to xpi0t0s's analysis of your code. mx does change during the output loop because you are assigning to it (in the fixed version). So you do still need mx2.

By the way, you should get used to using zero-based array subscripting, since that is the C/C++ way.