code works completely fine in case of NN array like 33, but showing some 0 values in case of NM arrays like 34 or 4*3 . Can you tell what’s wrong in this code and what changes it need.
CODE:
#include
using namespace std;
int main(){
int a[100][100];
int m,n;
cin>>m>>n;
int i,j;
for( i=0; i<m; i++){
for(j=0; j<n; j++){
cin>>a[i][j];
}
}
int k;
for(i=0;i<=m+n-2;i++){
for(j=0; j<m; j++){
for(k=0; k<n; k++){
if(j+k==i){
if(i%2==0){
cout<<a[k][j]<<" ";
}
else{
cout<<a[j][k]<<" ";
}
}
}
}
}
return 0;
}