one test case show error
#include
using namespace std;
void readmatrix(int arr[][10],int r,int c)
{
for(int i=0;i<r;++i)
{
for(int j=0;j<c;++j)
{
cin>>arr[i][j];
}
}
}
void sprialprint(int arr[][10],int r,int c)
{
int firstrow=0,lastrow=r-1,firstcol=0,lastcol=c-1;
while(firstrow<=lastrow && firstcol<=lastcol)
{
//print first column
for(int j=firstrow;j<=lastrow;++j)
{
cout<<arr[j][firstcol]<<", ";
}
++firstcol;
//print last row
for(int j=firstcol;j<=lastcol;++j)
{
cout<<arr[lastrow][j]<<", ";
}
--lastrow;
//print last col
if(firstcol<lastcol)
{
for(int j=lastrow;j>=firstrow;--j)
{
cout<<arr[j][lastcol]<<", ";
}
--lastcol;
}
//print first row
if(firstrow<lastrow)
{
for(int j=lastcol;j>=firstcol;--j)
{
cout<<arr[firstrow][j]<<", ";
}
++firstrow;
}
}
}
int main() {
int m,n;
cin>>m>>n;
int arr[10][10];
readmatrix(arr,m,n);
sprialprint(arr,m,n);
cout<<"END";
return 0;
}