Wave Print Column-Wise

My output is equivalent to the desired output. However on submitting,none of the test cases succeed.

My code :
#include
using namespace std;
int main() {
int m,n;
cin>>m>>n;
int arr[m][n];
for(int i=0; i<m; i++){
for(int j=0; j<n; j++){
cin>>arr[i][j];
}
}

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

}

Hello @gptradhika1208,

Mistake:
for(int i=n-1; i>=0; i–){
Solution:
It should be m-1 instead of n-1.

Hope, this would help.

Yes,it worked. Thanks

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.