Why is my code showing run error for anti-clockwise spiral print of 2D Array.
#include
using namespace std;
void Spiral_Print(int **A,int m,int n)
{
int startRow=0;
int startCol=0;
int endRow=m-1;
int endCol=n-1;
while(startRow<=endRow && startCol<=endCol)
{
int i;
for(i=startCol;i<=endCol;i++)
{
cout<<A[i][startRow]<<","<<" ";
}
startRow++;
for(i=startRow;i<=endRow;i++)
{
cout<<A[endCol][i]<<","<<" ";
}
endCol--;
if(endRow>startRow)
{
for(i=endCol;i>=startCol;i--)
{
cout<<A[i][endRow]<<","<<" ";
}
endRow--;
}
if(endCol>startCol)
{
for(i=endRow;i>=startRow;i--)
{
cout<<A[startCol][i]<<","<<" ";
}
startCol++;
}
}
cout<<"END";
}
int main()
{
int m,n,i,j;
cin>>m>>n;
int **A=new int*[m];
for(i=0;i<m;i++)
{
A[i]=new int[n];
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cin>>A[i][j];
}
}
Spiral_Print(A,m,n);
}