Take as input a two-d array. Wave print it column-wise.
Input Format
Two integers M(row) and N(colomn) and further M * N integers(2-d array numbers).
Take as input a two-d array. Wave print it column-wise.
Input Format
Two integers M(row) and N(colomn) and further M * N integers(2-d array numbers).
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.
Take as input a two-d array. Wave print it column-wise.
Input Format
Two integers M(row) and N(colomn) and further M * N integers(2-d array numbers).
Constraints
Both M and N are between 1 to 10.
Output Format
All M * N integers seperated by commas with ‘END’ wriiten in the end(as shown in example).
#include
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[10][10];
int m=0 , n=0;
cin>>m>>n;
for(int i = 0 ; i <m ; i++)
{
for(int j = 0 ; j <n ; j++)
{
cin >> a[i][j];
}
}
for(int j = 0 ; j<n ; j++)
{
if(j%2==0)
{
for(int i = 0 ; i < n ; i++)
{
cout<<a[i][j]<<",";
}
}
else
{
for(int i = m ; i <= 0 ; i--)
{
cout<<a[i][j]<<",";
}
}
}
cout<<"END";
return 0;
}
Test cases not passed
Please help
Correct code
#include
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[10][10];
int m=0 , n=0;
cin>>m>>n;
for(int i = 0 ; i <m ; i++)
{
for(int j = 0 ; j <n ; j++)
{
cin >> a[i][j];
}
}
for(int j = 0 ; j<n ; j++)
{
if((j%2) == 0)
{
for(int i = 0 ; i < m ; i++)
{
cout<<a[i][j]<<", ";
}
}
else
{
for(int i = m-1 ; i >= 0 ; i--)
{
cout<<a[i][j]<<", ";
}
}
}
cout<<"END";
return 0;
}
Thank you for your concern.
The problem is solved.