Array Spiral Print (Anticlockwise)

THIS IS MY CODE FOR THIS PROBLEM AND IN THE FIRST TEST CASE IT IS SHOWING WRONG ANSWER AND IT PASSES ALL THE OTHER TEST CASES…

SO WHAT’S THE MISTAKE IN THIS CODE ?

#include<bits/stdc++.h>

using namespace std;

void initial()
{
#ifndef ONLINE_JUDGE
freopen(“input.txt”,“r”,stdin);
freopen(“output.txt”,“w”,stdout);
#endif
}

void spiral(int arr[][10],int m,int n)
{
int startrow=0;
int startcol=0;
int endrow=m-1;
int endcol=n-1;

while(startrow<=endrow and startcol<=endcol)
{

	for(int i=startrow;i<=endrow;i++)
	{
		cout<<arr[i][startcol]<<", ";
	}

	startcol++;

	for(int i=startcol;i<=endcol;i++)
	{
		cout<<arr[endrow][i]<<", ";
	}

	endrow--;

	if(endcol>startcol)
	{
		 for(int i=endrow;i>=startrow;i--)
	   {
		cout<<arr[i][endcol]<<", ";
	   }

	endcol--;
	}

	if(endrow>startrow)
	{
		    for(int i=endcol;i>=startcol;i--)
	        {
	              	cout<<arr[startrow][i]<<", ";
	        }
	startrow++;
	}
}

}

int main()
{
initial();

int m,n;
cin>>m>>n;

int arr[10][10];

for(int i=0;i<m;i++)
{
	for(int j=0;j<n;j++)
	{
		cin>>arr[i][j];
	}
}

spiral(arr,m,n);

cout<<"END";

}

I have edited the code… Try to submit it now…