Spiral print problem

what is another method of this as this shows time limit excedding
#include
using namespace std;
int main()
{
int m;
int n;
cin>>m>>n;
int a[10][10];
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
cin>>a[i][j];
}
}
int sc=0;
int sr=0;
int er=m-1;
int ec=n-1;
while(sc<=ec&&sr<=ec)
{
for(int i=sr;i<=er;i++)
{
cout<<a[i][sc]<<", β€œ;
}
sc++;
for(int i=sc;i<=ec;i++)
{
cout<<a[er][i]<<”, β€œ;
}
er–;
while(sr>er&&sc>ec)
for(int i=er;i>=sr;i–)
{
cout<<a[i][ec]<<”, β€œ;
}
ec–;
for(int i=ec;i>=sc;i–)
{
cout<<a[sr][i]<<”, ";
}
sr++;
}
cout<<β€œEND”;
}

@dreamerekta here correct approach


i hope doubt is clear dont forget to mark it as resolved :smiley:

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.