About Spiral print of the array

#include
using namespace std;
#define R 10
#define C 10
void print(int arr[R][C], int i, int j, int m, int n)
{
if (i >= m or j >= n)
return;
for (int p = i; p < m; p++)
cout << arr[p][i] << ", ";
for (int p = i+1; p < n; p++)
cout << arr[n-1][p] << ", ";
if ((n - 1) != j)
for (int p = m - 2; p >= i; p–)
cout << arr[p][n-1] << ", ";
if ((m - 1) != i)
for (int p = n - 2; p > j; p–)
cout << arr[i][p] << ", ";
print(arr, i + 1, j + 1, m - 1, n - 1);
}
int main() {
int m,n;
cin >> m >> n;
int arr[R][C];
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
cin>>arr[i][j];
}
}
print(arr,0,0,m,n);
cout<<“END”;
return 0;
}
Tell Me the Error in this code, It is printing the same output as in question but when I submit it all the test cases are wrong.

Hello @dhwaj_gupta,

Run your code for the following testcase to understand your mistake:
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
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

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

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.