out of 4 testcases, 3 are correct and 1 is wrong and i am not getting where my code has gone wrong
the code is-
#include
using namespace std;
int main() {
int r,c;
cin>>r>>c;
int a[100][100];
int i,j;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
cin>>a[i][j];
}
}
int startrow=0,endrow=r-1;
int startcol=0,endcol=c-1;
while((startrow<=endrow)&&(startcol<=endcol))
{
for(i=startrow;i<=endrow;i++)
{
cout<<a[i][startcol]<<", ";
}
startcol++;
for(j=startcol;j<=endcol;j++)
{
cout<<a[endrow][j]<<", ";
}
endrow--;
if(startcol<endcol)
{
for(i=endrow;i>=startrow;i--)
{
cout<<a[i][endcol]<<", ";
}
endcol--;
}
if(startrow<endrow)
{
for(j=endcol;j>=startcol;j--)
{
cout<<a[startrow][j]<<", ";
}
startrow++;
}
}
cout<<"END";
return 0;
}