Array wave generation

sir i dont uncerstanding why my cases are having worng answer in cheked it manually on dev by pasting the same code multiple time and running on different output
#include
using namespace std;
int main() {
int i,j;
int M,N;
cin>>M>>N;
if(11>M>0 && 11>N>0)
{
int arr[M][N];
for(i=0;i<M;i++)
{
for(j=0;j<N;j++)

    {
        cin>>arr[i][j];
    }
}
for(i=0;i<M;i++)
{ 
    if(i==0)
    { 
       for(j=0;j<N;j++)
       {
           cout<<arr[j][i]<<", ";
       }  
    } 
    if(i==1)
    {
        for(j=N-1;j>=0;j--)
        {
            cout<<arr[j][i]<<", ";
        }
    }
        
    
    if(i>=2 && i%2==0)
    {
        for(j=0;j<N;j++)
       {
           cout<<arr[j][i]<<", ";
       } 
        
    }
     if(i>=2 && i%2!=0)
    {
        for(j=N-1;j>=0;j--)
       {
           cout<<arr[j][i]<<", ";
       } 
        
    }
}

cout<<"END";
}

return 0;

}

Hi @sourabhsingh282
When you are printing the array you have used N and M at each others place. Just replace all N by M and vice versa in the for loop and if conditions after taking inputs from user.

Here is your corrected code :

https://ide.codingblocks.com/s/165479

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.