Array-Spiral Print

1 test case passed out of 2

#include
using namespace std;

int main() {
int m,n;
cin>>m>>n;
int sr=0,sc=0,ec=n-1,er=m-1;
int arr[m][n];
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
cin>>arr[i][j];
}
}
// for(int i=0;i<m;i++){
// for(int j=0;j<n;j++){
// cout<<arr[i][j];
// }
// }
while(sr<=er && sc<=ec){
for(int col=sc;col<=ec;col++){
cout<<arr[sr][col]<<", β€œ;
}
sr++;
for(int row=sr;row<=er;row++){
cout<<arr[row][ec]<<”, β€œ;
}
ec–;
if(sr<er)
{ for(int col=ec;col>=sc;col–){
cout<<arr[er][col]<<”, ";
}

er--;

}
if(sc<ec){
for(int row=er;row>=sr;row–){
cout<<arr[row][sc]<<", ";
}
sc++;
}
}
cout<<β€œEND”;
return 0;
}

@shuja33
corrected code -->

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.