Example is running well but other cases are failed
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
ll m,n;
cin>>m>>n;
ll ar[m][n];
for(ll i=0;i<m;i++)
{
for(ll j=0;j<n;j++)
{
cin>>ar[i][j];
}
}
for(ll i=0;i<m;i++)
{
for(ll j=0;j<n;j++)
{
cout<<ar[j][i]<<" β;
}
cout<<β\n";
}
}
Why my code is not working
@the.shubham.sri
you are printing columnwise but you need to print it in wave manner i.e
first column (from first row to last row)
second column ( from last row to first row)
third coulmn ( from first row to last row)
fourth column ( from last row to first row)
so on.
check below example

#include < iostream>
using namespace std;
int main() {
int n,m,i,j;
cin>>n>>m;
int arr[n][m];
for(i=0;i<n;i++)
for(j=0;j<m;j++)cin>>arr[i][j];
for(i=0;i<m;i++)
{
if(i%2)
{
for(j=n-1;j>=0;jβ)
cout<<arr[j][i]<<", β;
}
else
for(j=0;j<n;j++)
cout<<arr[j][i]<<β, ";
}
cout<<βENDβ;
return 0;
}
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.