Spiral print column wise

#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

Hi @arsh_goyal,
I have updated ur code and commented whatever changes were needed.


Hope this resolves ur doubt.

Hi,
I hope ur doubt was resolved.
If it was, pls mark dis doubt resolved.
else if u r still having any doubts regarding dis question, u can post them here

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

Hi , the doubt is still unresolved .Please help

Please copy paste your code in coding blocks IDE. Save it and send the link.

Hi @arsh_goyal
Here is the corrected code.


All the changes made have been commented.
If u still feel like something is unclear, feel free to post ur doubt here.
Hope dis will help.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.