Spiral print anti clock wise

1 test case failing…please help
this is my code

Sure @Bansaljatin05,

Please share your code.
Steps:

  1. Paste your code on https://ide.codingblocks.com/
  2. Save it there.
  3. Share the URL generated.

Hello @Bansaljatin05,

You code is failing for the testcase like:
Example:
4 6
11 12 13 14 15 16
21 22 23 24 25 26
31 32 33 34 35 36
41 42 43 44 45 46
Your Output:
11, 21, 31, 41, 42, 43, 44, 45, 46, 36, 26, 16, 15, 14, 13, 12, 22, 32, 33, 34, 35, 25, 24, 23, 24, END
Expected Output:
11, 21, 31, 41, 42, 43, 44, 45, 46, 36, 26, 16, 15, 14, 13, 12, 22, 32, 33, 34, 35, 25, 24, 23, END

Solution:
//prints end col
if(startcol <= endcol)
{for(int i=endrow;i>=startrow;i–){
cout<<arr[i][endcol]<<", “;
}
endcol–;}
//prints start row
if(startrow <= endrow){
for(int i=endcol;i>=startcol;i–){
cout<<arr[startrow][i]<<”, ";
}

Hope, this would help.
Give a like if you are satisfied.

1 Like

My output also goes wrong 2×n(n>3)matrix or for nx2 matrix

Hey @Bansaljatin05,

After correcting the modification that i have specified in my previous reply, your code will pass all the test cases.

Modified Code:

1 Like