#include<bits/stdc++.h>
using namespace std;
int main(){
int r,c;
cin>>r>>c;
int a[r][c];
for(int i=0;i<r;i++){
for(int j=0;j<c;j++){
cin>>a[i][j];
}
}
int sr,er,sc,ec;
sr=0;
er=r-1;
sc=0;
ec=c-1;
while((sr<=er) and (sc<=ec)){
for(int i=sr;i<=er;i++){
cout<<a[i][sc]<<", ";
}
sc++;
for(int i=sc;i<=ec;i++){
cout<<a[er][i]<<", ";
}
er--;
if(ec>sc){
for(int i=er;i>=sr;i--){
cout<<a[i][ec]<<", ";
}
ec--;}
if(er>sr){
for(int i=ec;i>=sc;i--){
cout<<a[sr][i]<<", ";
}
sr++;}
}
cout<<"END";
}
if the input is
2 6
1 2 3 4 5 6
7 8 9 10 11 12
i am getting output
1 7 8 9 10 11 12 6 2 3 4 5
but the correct output should be 1 7 8 9 10 11 12 5 4 3 2
whats wrong in my code.