Wave printing of matrix

#include
using namespace std;

int main() {
int row,col;
cin>>row>>col;
int arr[row][col];

//TAKES INPUT IN ARRAY
for(int i=0;i<row;i++)
{
for(int j=0;j<col;j++)
{
cin>>arr[i][j];

     }
 }

int rowstart=0,rowend=row-1;

for(int i=0;i<col;i++)
{

 //CHECKS IF COL IS EVEN IF YES THEN PRINTS FROM TOP TO BOTTOM 
 if(i%2==0)    
 {
   while(rowstart!=row)
    {
      cout<<arr[rowstart][i]<<",";  //PRINTS FROM TOP TO BOTTOM 
      rowstart++;
    }
    rowstart=0;
  }


//IF COL IS ODD THEN PRINTS FROM  BOTTOM TO TOP
 else        
 {
   while(rowend>=0)
       {
       cout<<arr[rowend][i]<<",";  //PRINTS FROM  BOTTOM TO TOP
       rowend--;
       }
    rowend=row-1;
  }

}
cout<<“END”;
return 0;
}

where i am wrong someone please help me out…its giving wrong answer on testcases

Hey, your output should exactly match the given output format of the problem. There is space after ", " in the output format that you haven’t given. So, replace"," with ", " in your code.

i tried this too :confused: @sanjeetboora

Add the problem link.

Your code is passing all the test cases once “,” is replaced by ", "
https://ide.codingblocks.com/s/43220

Hey Vishnupriya, do the suggested change in the code you provided and retry to submit it.

1 Like

yeah i tried it ran …thanks:blush:

thank you very much…
wasted hell a lot of time just because of that…