Anticlockwise unexpecte wrong answer

Can anyone please tell me where i gone wrong .
Here’s my code.
#include
using namespace std;

int main() {

int m , n ;
cin>>m>>n;

int a[10][10];
int startrow =0 , startcol=0 , endrow=m-1 , endcol=n-1;
for(int i=0 ; i<m ; i++){
    for(int j=0 ; j<m ; j++){
        cin>>a[i][j];
    }
}

while(startrow<endcol && startcol<endcol){
    
    //orint first col
    for(int i=startrow ; i<=endrow ; i++){
        cout<<a[i][startcol]<<", ";
    }
    startcol++;
    
     //print last row
    if(endrow>startrow){
    for(int i=startcol ; i<=endcol ; i++){
        cout<<a[endrow][i]<<", ";
    }
    endrow--;
    }
    
     //print last col
    if(endcol>startcol){
    for(int i=endrow ; i>=startrow ; i--){
        cout<<a[i][endcol]<<", ";
    }
    endcol--;
    }
    
    //print first row
    for(int i=endcol ; i>=startcol ; i--){
          cout<<a[startrow][i]<<", ";  
    }
    startrow++;
   
}
cout<<"END";
return 0;

}

Plz send your code by saving on ide only

There are certain errrors with your code, Use
while(startrow<=endrow && startcol<=endcol)
Maintain a variable : int direction=0;
and before every loop , check wht is the value of direction and along with that update the value of direction :
if(direction==0)
{
for(int i=top;i<=bottom;i++)
{
cout<<ar[i][left]<<","<<" ";
}
left++;
direction=1;
}

Do like this… and then try to submit