Ake as input a two-d array. Wave print it column-wise

#include
int main() {
int M,N;
std::cin>>N;
std::cin>>M;
if(M>1&&M<10){
if(N>1&&N<10){

 int arr[M][N]={0};
int i,j;
for(i=0;i<=N;i++){
    for(j=0;j<=M;j++){
        std::cin>>arr[j][i];
    }
}
for(i=0;i<=N;i++){
    for(j=0;j<=M;j++){
        std::cout<<arr[j][i]<<",";
 }
}
std::cout<<"END";
}}return 0; 

}

answer is wrong why

anoushka u r just inputing the array and outputing it
u have to do like
1 2 3
4 5 6
7 8 9
make a wave column wise output 1 4 7 8 5 2 3 6 9
so u have to print column first top to down then second column down to up and same patter for next column

I am still not able to do it

u jus thave to print like a wave
just make the above matrix on a paper and connect the point i have show as output u will see a wave

As wave is continous so u have to print continous elemnt column wise
like first column 1 4 7 next if u go to element 2 then its not continous so u have to print 8 5 2 h then 3 6 9
n is no of rows and m is no of column
for(int i=0;i<m;i++){
if i%2==0 // then u have to print top to down
for (int j=0;j<n;j++){
cout<<a[i][j]
else // i is odd u have to print bottom to top
for (int i=n-1;i>=0;i–)
cout<<a[i][j]
dry run this code on the above matrix
hope this help :slight_smile:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

hi!
here is my code to the same problem.It was compiled successfully and is giving the same result as shown but its not passing any test cases, can u plis tell what is wrong with my code
#include
using namespace std;
int main() {
int M,N;
cin>>M;
cin>>N;
if(M>1 && M<10){
if(N>1 && N<10){
int a[M][N]={0};
int i,j;
for(i=0;i<M;i++){
for(j=0;j<N;j++){
cin>>a[i][j];
}
}
for(i=0;i<N;i++){
if(i%2==0){
for(j=0;j<M;j++){
cout<<a[j][i]<<",";
}
}
else{
for(j=M-1;j>=0;j–){
cout<<a[j][i]<<",";
}
}
}
cout<<“END”;
}
}
return 0;
}