Not able to find error

output is fine but something wrong in code and I am not able to find out.

Hello @rprahulpal03 please share your code so that I can see .

#include
using namespace std;

int main()
{
int m,n;
cin>>m>>n;
int Array2D[m][n];

for (int i = 0; i < m; i++)
{
    for(int j=0; j<n;j++)
    {
        cin>>Array2D[i][j];
    }
}

for (int i = 0; i < m; i++)
{
    for(int j=0; j<n;j++)
    {
        cout<<Array2D[i][j]<<" ";
    }
    cout<<endl;
}
int startcol =0;
int startrow =0;
int endrow=n-1;
int endcol=m-1;

 while (startrow <=endrow && startcol<=endcol )
{
    for (int i = startrow; i <= endrow; i++)
    {
        cout<<Array2D[i][startcol]<<", ";
    }
    startcol++;

    for (int i = startcol; i <=endcol; i++)
    {
        cout<<Array2D[endrow][i]<<", ";
    }
    endrow--;

    if (endrow>startrow)
    {
        for (int i = endrow; i >=startrow ; i--)
        {
        cout<<Array2D[i][endcol]<<", ";
        }
        endcol--;
    }
    if (endcol>startcol)
    {
        for (int i = endcol; i >=startcol ; i--)
        {
        cout<<Array2D[startrow][i]<<", ";
        }
        startrow++;
    }  
    
}
cout<<"END";

}

Hello @rprahulpal03 i have corrrected your code and commented the mistake:


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.