For a given two-dimensional integer array/list of size (N x M), print the array/list in a sine wave order, i.e, print the first column top to bottom, next column bottom to top and so on.
I am unable to get the expected output for this problem. Please find my code below:
#include <bits/stdc++.h>
using namespace std;
void wavePrint(int input[][2], int nRows, int mCols)
{
//Write your code here
for(int i=0;i<mCols;i++){
int j=0;
for(;j<nRows;j++){
cout<<input[j][i]<<" ";
}
i++;
for(;j>=0;j--){
cout<<input[j][i]<<" ";
}
}
}
int main()
{
int input[][2]={{5,6},{2,4}};
wavePrint(input, 2, 2);
cout << endl;
}
j
in your current program, resulting in printing garbage value.