All code is correct, sample case run perfectly but test cases goes fail

#include
using namespace std;
int main() {

int n,m;
cin >> n >> m;

int a[n][m];
int i,j;


if(n>=1 && n<10){
	if(m>=1 && m<10){
		for(i=0;i<n;i++){
	      for(j=0;j<m;j++){
		    cin >> a[i][j];
		}	
	}
}

for(i=0; i<n; i++){
	if(i%2==0){
		for(j=0; j<m; j++){
			cout << a[j][i] << "," << " ";
		}
	}
	else {
		for(j=m-1; j >=0; j--){
			cout << a[j][i] << ","<<" ";
		}
	}
 }
 cout << "END";
}
return 0;

}

hi @harshitmehandiratta1425_96c35b41b94f8e55 refer