About wave print of an matrix

in printing a matrix we, let say we took R and C as rows and columns and we use for loop then our for loop first takes row no 0 and then will print all the columns element i.e iterate column over row. But if we want to iterate rows over columns,as done by prateek he just replaced R by C aand vice cersa. So how our program know that the first loop is of columns not for rows. acoording to me the if ealier R=2 and C=3 then after changing R and C the result should be 3 Rows with 2coluns and the 3rd row should contain garbage values

Hey Satvik, it just depends upon how you are accessing the elements of the matrix. for eg
input:
3 4
1 2 3 4
11 12 13 14
21 22 23 24

  int r,c;
    cin>>r>>c;
    int matrix[r][c];
    for(int row=0; row<r; row++){
        for(int col=0; col<c; col++){
            cin>>matrix[row][col];
        }
    }
    // iterate column over row
    for(int row=0; row<r; row++){
        for(int col=0; col<c; col++){
            cout<<matrix[row][col]<<" ";
        }
        cout<<endl;
    }
     // iterate row over column
     for(int col=0; col<c; col++){
         for(int row=0; row<r; row++){
            cout<<matrix[row][col]<<" ";
        }
        cout<<endl;
     }

output:
1 2 3 4
11 12 13 14
21 22 23 24
1 11 21
2 12 22
3 13 23
4 14 24

#include

int main() {

int arr[1000][1000];

int m,n,i,j;

std::cin>>m;

std::cin>>n;

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

    for(j=0;j<n;j++)

    {

        std::cin>>arr[i][j];

    }

}

for(j=0;j<n;j++)

{

    if(j%2==0){

        for(i=0;i<m;i++){

            std::cout<<arr[i][j];

        }

    }

    else{

        for(i=m;i>0;i++){

            std::cout<<arr[i][j];

        }

    }

}

return 0;

}

could anyone please tell me whats the error in this?