#include<bits/stdc++.h>
using namespace std;
int main() {
int n,m,f=0;
int arr[10][10];
cin>>n>>m;
if(m%2==0)
{
f==1;
}
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
cin>>arr[i][j];
}
}
for(int i=0;i<m;i++)
{
if(i%2==0)
{
for(int r=0;r<n;r++)
{ if((i==m-1)&&(f==0)&&(r==n-1))
{cout<<arr[r][i]<<", END";
return 0;
}
cout<<arr[r][i]<<',';
}
}
else
{
for(int r=n-1;r>=0;r--)
{ if((i==m-1)&&(f==1)&&(r==0))
{cout<<arr[r][i];
cout<<", END";
return 0;
}
cout<<arr[r][i]<<',';
}
}
}
return 0;
}
this is my code.
first I am dividing m by 2, to decide where i have to print END
then have two loops, from up to down and vice-versa
in loop, i am checking, if this is the last column, last row and f==1(when number of column is even), if it is so, i orint end and return,
this works for odd number of columns, but not for even number. why so?