Why my code is not working

Example is running well but other cases are failed
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
ll m,n;
cin>>m>>n;
ll ar[m][n];
for(ll i=0;i<m;i++)
{
for(ll j=0;j<n;j++)
{
cin>>ar[i][j];
}
}
for(ll i=0;i<m;i++)
{
for(ll j=0;j<n;j++)
{
cout<<ar[j][i]<<" β€œ;
}
cout<<”\n";
}
}

@the.shubham.sri
hello shubham,
please share ur code using coding blocks ide

@the.shubham.sri
you are printing columnwise but you need to print it in wave manner i.e
first column (from first row to last row)
second column ( from last row to first row)
third coulmn ( from first row to last row)
fourth column ( from last row to first row)
so on.
check below example

image

@the.shubham.sri
hello shubham,
if ur doubt is resolved then pls mark it as resolved

#include < iostream>
using namespace std;
int main() {
int n,m,i,j;
cin>>n>>m;
int arr[n][m];
for(i=0;i<n;i++)
for(j=0;j<m;j++)cin>>arr[i][j];
for(i=0;i<m;i++)
{
if(i%2)
{
for(j=n-1;j>=0;j–)
cout<<arr[j][i]<<", β€œ;
}
else
for(j=0;j<n;j++)
cout<<arr[j][i]<<”, ";
}
cout<<β€œEND”;
return 0;
}

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.