This code is showing my output as "END" on hqackerblocks but other compilers are showing that it is correct as needed

#include //
using namespace std;
int main() {
int N,M;
cin>>N>>M;
int A[N][M];
for(int i=0; i<N; i++)
for(int j=0; j<M; j++)
cin>>A[i][j];

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

}

I have used comment operator thtat is not creating any error

Hello @AyushKumar9032,

There is logical error:
//You have to print column wise
//N is for row and M is for columns
//for(int i=0; i<N; i++)
for(int i=0; i<M; i++)
{
if(i%2==0)
{
//for(int j=0; j<M; j++)
for(int j=0; j<N; j++)
{
cout<<A[j][i]<<", “;
}
}
else{
//for(int j=M-1; j>=0; j–)
for(int j=N-1; j>=0; j–)
{
cout<<A[j][i]<<”, ";
}
}
}

Hope, this would help.
Give a like if you are satisfied.

1 Like

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.