Spiral printing

i have written a code for 2d array which takes no. of rows and column as an input from user …and after that i have applied my code for printing elements of array in spiral way…i am writing my code down here please review it.

#include
using namespace std;
int main() {
int m,n;
int a[m][n];
int sr = 0;
int sc = 0;
int er = m-1;
int ec = n-1;
cout<<"Enter the no of rows in matrix : "<<endl;
cin>>m;
cout<<"Enter the no of colums in matrix : "<<endl;
cin>>n;
for(int row =0;row<m;row++)
{
for(int col = 0;col<n;col++)
{
cout<<"enter the element at row “<<row<<” and at “<<col<<” : “;
cin>>a[row][col];
}
}
while(sr <= er && sc<= ec)
{
for(int i = sc;i<=ec;i++)
{
cout<<a[sr][i]<<” “;
}
sr++;
for(int i = sr;i<=er;i++)
{
cout<<a[i][ec]<<” ";
}
ec–;
if(er>sr)
{
for(int i = ec;i>=sc;i–)
{
cout<<a[er][i]<< " “;
}
er–;
}
if(ec>sc)
{
for(int i = er;i>=sr;i–)
{
cout<<a[i][sc]<<” ";
}
sc–;
}

}

return 0;
}

@Gaurav_dev please save your code on ide.codingblocks.com and share the link :slight_smile:

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.