Wave print problem

what is wrong in this code as output is perfect but not matching
#include
using namespace std;
int main() {
int c,r;
cin>>r>>c;
int a[r][c];
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
cin>>a[i][j];
}
}
for(int i=0;i<r;i++)
{
if(i%2==0)
{
for(int j=0;j<c;j++)
{
cout<<a[j][i]<<", β€œ;
}
}
else{
for(int j=c-1;j>=0;j–)
{
cout<<a[j][i]<<”, ";
}
}
}
cout<<β€œEND”<<endl;
return 0;
}

see there is some logical problem

u need to print row wise and traverse column wise
go from col 0 to c
and for each element to be printed go from 0 to r-1
else r-1 to 0

for (int i = 0; i < c; i++)
{
if (i % 2 == 0)
{
for (int j = 0; j < r; j++)
{
cout << a[j][i] << ", ";
}
}
else
{
for (int j = r-1; j >= 0; j–)
{
cout << a[j][i] << ", ";
}
}
}

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.