Why not any testcase give correct

in array wave column wise my code give answer after compiling but after submission all test case failed what is the wrong in this code
#include
using namespace std;
int main() {
int n,m;
int a[100][100];
cin>>n>>m;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
cin>>a[i][j];
}
}
for(int i=0;i<n;i++)
{
if(i%2==0)
{
for(int j=0;j<m;j++)
{
cout<<a[j][i]<<","<<" ";
}

	}
	else
	{
		for(int j=(m-1);j>=0;j--)
		{
			cout<<a[j][i]<<","<<" ";
		}
	}
	
}
cout<<"END";
return 0;

}

@76vpsingh well your code was giving wrong for
2 3
1 2 3
4 5 6
corrected


dont forget to mark the doubt resolved and hit like if cleared :smiley:

what did you correct buddy i am having the same problem

@malhotranaman83 in his code n was columns and m was rows but he was doing m as n and vice versa.
you share your code so i can check

import java.util.*;
public class Main {
public static void main(String args[]) {
int n,m;
Scanner sc=new Scanner(System.in);
n=sc.nextInt();
m=sc.nextInt();
int[][] arr=new int[n][m];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
arr[i][j]=sc.nextInt();
}
}

waveprint(arr);
}
public static void waveprint(int[][] arr){
int j=0;

for(int i=0;i<arr.length;i++){
	if(i%2==0){
	for(j=0;j<arr[i].length;j++){
			System.out.print(arr[j][i]+", ");}}

else{for(j=arr[i].length-1;j>=0;j–){
System.out.print(arr[j][i]+", ");
}}}
System.out.print(“END”);

		}

}

sorry bro don’t know java :sweat_smile:

1 Like

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.