Array-spiral print anticlock wise

#include
using namespace std;

void spiral(int arr[100][100], int M, int N)
{
int sc = 0, sr = 0, ec = N - 1, er = M - 1;
while (sc <= ec and sr <= er)
{
// print sc
for (int row = sr; row <= er; row++)
{
cout << arr[row][sc] << ", ";
}
sc++;

    // print er
    for (int col = sc; col <= ec; col++)
    {
        cout << arr[er][col] << ", ";
    }
    er--;
    if (sc < ec)
    {

        // print ec
        for (int row = er; row >= sr; row--)
        {
            cout << arr[row][ec] << ", ";
        }
        ec--;
    }

    if (sr < er)
    {

        // print sr
        for (int col = ec; col >= sc; col--)
        {
            cout << arr[sr][col] << ", ";
        }
        sr++;
    }
}

}
int main()
{
int M, N;
cin >> M >> N;
int arr[100][100];

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

spiral(arr, M, N);

return 0;

}

here is my code cleared all test case except 4th one
plz help me out

@sahilkumar23102003_bbf6ee38349d98a1 u just flipped the conditions of if block
sc<ec and sr<er thing here’s the updated code https://ide.codingblocks.com/s/658992

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.