Help me in solving DSAAGP51 problem

My issue

please find my mistake only a single digit mistake in whole output

My code

#include <stdio.h>

int main() {
	// your code goes here
 int i,j,N,M;
  scanf("%d",&N);
   scanf("%d",&M);
   int a[N][M],b[N][M];
   for(i=0;i<N;i++)
        {
            for(j=0;j<M;j++)
                {
                    scanf("%d",&a[i][j]);
                }
        }
    for(i=0;i<N;i++)
        {
            for(j=0;j<M;j++)
                {
                    b[j][i]=a[i][j];
                }
        }
    for(i=0;i<M;i++)
        {
            for(j=0;j<N;j++)
                {
                    printf("%d ",b[i][j]);
                }
        printf("\n");
        }
    return 0;
}


Learning course: BCS301: Data structures
Problem Link: https://www.codechef.com/learn/course/abesit-dsa/ABESITDS09/problems/DSAAGP51