#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