I have run the code on the coding blocks ide and its running fine there but here the 2d array is printing the garbage values. please help me finding the mistake.
THE CODE IS AS FOLLOWS:-
#include
using namespace std;
int main() {
int m , n ;
cin>>m>>n;
// initialisation and declaration of the array
int a[m][n];
for(int k=0;k<m;k++){
for(int l=0;l<n;l++){
cin>>a[k][l];
}
}
//spiral print
int startRow=0;
int endRow=m-1;
int startCol=0;
int endCol=n-1;
while(startRow<=endRow && startCol<=endCol){
for(int i=startRow;i<=endRow;i++){
cout<<a[i][startCol]<<", ";
}
startCol++;
for(int i=startCol;i<=endCol;i++){
cout<<a[endRow][i]<<", ";
}
endRow--;
if(endCol>=startCol){
for(int i=endRow;i>=startRow;i--){
cout<<a[i][endCol]<<", ";
}
endCol--;
}
if(startRow<=endRow){
for(int i=endCol;i>=startCol;i--){
cout<<a[startRow][i]<<", ";
}
startRow++;
}
}
cout<<"END";
return 0;
}