Spiral question

#include
using namespace std;

void spiral(int n,int m, int arr[][m]){
int sr=0;
int sc=0;
int er=n-1;
int ec=m-1;
while(sr<=er&& sc<=ec ){
for ( int col = sc; col <=ec; ++col)
{
cout<<arr[sr][col]<<’ ';
}
sr++;

	for ( int row = sr; row <= er; ++row)
	{
		cout<<arr[row][ec]<<' ';
	}
	ec--;
	for ( int col = ec; col >=0; col--)
	{
		cout<<arr[er][col]<<' ';
	}
	er--;

	for ( int row = er; row >= sr; row--)
	{
		cout<<arr[row][ec]<<' ';
	}
	sc++;
}

}
int main()
{
int n,m;
cin>>n>>m;
int arr[n][m];
int val=1;
for (int row = 0; row < n; ++row)
{
for (int col = 0; col < m; ++col)
{
cout<<val<<’ ';
val++;
}
cout<<endl;
}

spiral(n,m,arr[n][m]);
return 0;

// not able to understand the mistake

hi @srivastavaayush1611_3fd51b257da0b834 use if conditions in 3rd and 4th conditions it will fail of 3*4 or 4*3 matrix
refer 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.