#include
using namespace std;
int main() {
int m,n;
cin>>m>>n;
int startcol=0,startrow=0,endcol=n-1,endrow=m-1;
int arr[m][n];
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
cin>>arr[i][j];
}
}
while(startrow<=endrow && startcol<=endcol)
{
for(int i=0;i<=n-1;i++)
{
cout<<arr[i][startcol]<<",";
}
startcol++;
for(int j=startcol;j<=endcol;j++)
{
cout<<arr[endrow][j]<<",";
}
endrow--;
if(endcol>startcol)
{
for(int i=endrow;i>=startrow;i--)
{
cout<<arr[i][endcol]<<",";
}
}
endcol--;
if(startrow<endrow)
{
for(int i=endcol;i>=startcol;i++)
{
cout<<arr[startrow][i]<<",";
}
}
startrow++;
}
return 0;
}
Pleae let me know the mistake