This code gives correct output and the code used is same as taught in one of the course videos, so why does it pass only 50% test cases

#include
using namespace std;

void spiralprint(int a[1000][1000],int m,int n)
{
int sc=0,ec=n-1,sr=0,er=m-1,i,j;
while(sr<=er&&sc<=ec)
{

    for(i=sc;i<=ec;i++)
        cout<<a[sr][i]<<","<<" ";
    sr++;

    for(i=sr;i<=er;i++)
        cout<<a[i][ec]<<","<<" ";
    ec--;
    if(sr<er)
    {
        for(i=ec;i>=sc;i--)
            cout<<a[er][i]<<","<<" ";
        er--;
    }

    if(sc<ec)
    {
         for(i=er;i>=sr;i--)
            cout<<a[i][sc]<<","<<" ";
        sc++;
    }

}

cout<<"END";

}

int main() {
int m,n,a[1000][1000],i,j;
cin>>m>>n;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
cin>>a[i][j];
}

spiralprint(a,m,n);

return 0;

}

change it to
sr<=er

similarly

also change it to sc<=ec

now your code pass all testcases

yes it is working now

@muskanrathore01_4aab76aa7dafc189
kindly give your feedback asap from link below
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.