Not sure whether declaring array like this will work or not.
Showing the same output required for the input given but on submitting all test cases getting failed
here is the source code. Need to print the array in the wave form.
#include
using namespace std;
int main() {
int n,m;
cin>>m>>n;
int arr[m][n];
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
cin>>arr[i][j];
}
}
int i=0;
int j=0;
for( i;i<m;i++){
if(j<n){
j=0;
for( j;j<n;j++){
cout<<arr[j][i]<<", ";
}
}
else{
j=n-1;
for( j;j>=0;j--){
cout<<arr[j][i]<<", ";
}
}
}
cout<<"END";
}
Giving correct output for the sample input but on submitting showing all test cases failed.
Your code is producing error. So i would suggest that you use some other approach in your code. One such approach can be that you can take a direction variable, initializing to 1 and then for every direction print the array and then increment the value of direction variable.