

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


#include <stdio.h>
int main(void) { int t; int m,n,i,l,top,r,b,count,j; int a[100][100]; scanf("%d",&t); while(t--) { scanf("%d%d",&m,&n); for(i=0;i<m;i++) for(j=0;j<n;j++) scanf("%d",&a[i][j]); l=0; top=0; r=n-1; b=m-1; count=0; while(1) { for(i=top;i<=r;i++) { printf("%d ",a[top][i]); count++;
} for(i=top+1;i<=b;i++) { printf("%d ",a[i][r]);
count++;
for(i=r-1;i>=l;i--) { printf("%d ",a[b][i]); count++; } for(i=b-1;i>top;i--) { printf("%d ",a[i][l]); count++; } if(count==m*n) break; top++; r--; b--; l++;
}
return 0; }