Spiral matrix anticlockwise

#include
using namespace std;
int main()
{
int m,n;
cin>>m>>n;
int a[m][n];
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
cin>>a[i][j];
int rs=0,cs=0;
int re=m-1,ce=n-1;

while(rs<=re && cs<=ce)
{

for(int i=rs;i<=re;i++)
{
    cout<<a[i][cs]<<", ";
}
cs++;
for(int i=cs;i<=ce;i++)
{
    cout<<a[re][i]<<", ";

}
re--;
if(cs<ce)
{for(int i=re;i>=rs;i--)
{cout<<a[i][ce]<<", ";
    }
    ce--;}
    if(rs<re)
    {for(int i=ce;i>=cs;i--)
    {
        cout<<a[rs][i]<<", ";
    }
    rs++;}

}
cout<<“END”;
}

what is wrong in this code? it fails for 1 test case.

@sdevesh29 check for equality too where you are checking if(cs<ce) and at if(rs<re).

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.