what is wrong in this code as output is perfect but not matching
#include
using namespace std;
int main() {
int c,r;
cin>>r>>c;
int a[r][c];
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
cin>>a[i][j];
}
}
for(int i=0;i<r;i++)
{
if(i%2==0)
{
for(int j=0;j<c;j++)
{
cout<<a[j][i]<<", β;
}
}
else{
for(int j=c-1;j>=0;jβ)
{
cout<<a[j][i]<<β, ";
}
}
}
cout<<βENDβ<<endl;
return 0;
}
Wave print problem
see there is some logical problem
u need to print row wise and traverse column wise
go from col 0 to c
and for each element to be printed go from 0 to r-1
else r-1 to 0
for (int i = 0; i < c; i++)
{
if (i % 2 == 0)
{
for (int j = 0; j < r; j++)
{
cout << a[j][i] << ", ";
}
}
else
{
for (int j = r-1; j >= 0; jβ)
{
cout << a[j][i] << ", ";
}
}
}
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.