Spiral print problem

the last element is coming wrong in 44 matrix.
and the last element is printed extra in 5
3 matrix.
please help me to get this correct and send the complete code again with corrections

Please answer my questions. its already 24 hours.
where is the TA?