It seems very easy problem of just printing 2D matrix in some format. But it includes many corner cases which needs to be taken care of. Such problems can test your coding practice.
Following is implementation of above problem in c language.
Please write comments if you find anything wrong or you want to add something more related to this topic.