One testcase is failing. Not getting why

#include

using namespace std;
void printSpiral(int row, int col, int arr[][50])
{
int sr=0, sc=0, er = row - 1, ec = col-1;
if(row == 1 && col == 1)
cout << arr[row][col] << “, END”;

while(er>sr && ec>sc)
{
	for(int i=sr; i<=er; i++)
		cout << arr[i][sc] << ", ";
	sc++;

	for(int j=sc;j<=ec; j++)
		cout << arr[er][j] << ", ";
	er--;

	if (sc <= ec) {
		for(int k=er; k>=sr; k--)
			cout << arr[k][ec] << ", ";
		ec--;
	}

	if(sr <= er) {
		for(int l=ec; l>=sc; l--)
			cout << arr[sr][l] << ", ";		
		sr++;
	}
}
cout << "END";

}

int main() {
static int row, col;
cin >> row >> col;
int arr[50][50];
for(int i=0; i<row; i++)
{
for(int j=0; j<col; j++)
cin >> arr[i][j];
}
printSpiral(row, col, arr);
return 0;
}

Hello @mramanjain i have corrected your code and now it is passing every test case you can check the code now.


if you have any doubt you can ask here:
if you feel that your doubt is cleared you can mark this doubt as resolved.
Happy Learning!!

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.