Skip to content

Commit c5abb01

Browse files
authored
Wave print solution added
1 parent 85ace55 commit c5abb01

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/* Hacker Blocks */
2+
/* Title - Wave Print Column Wise */
3+
4+
// Take as input a two-d array. Wave print it column-wise.
5+
6+
// Input Format
7+
// Two integers M(row) and N(colomn) and further M * N integers(2-d array numbers).
8+
9+
// Constraints
10+
// Both M and N are between 1 to 10.
11+
12+
// Output Format
13+
// All M * N integers seperated by commas with 'END' wriiten in the end(as shown in example).
14+
15+
// Sample Input
16+
// 4 4
17+
// 11 12 13 14
18+
// 21 22 23 24
19+
// 31 32 33 34
20+
// 41 42 43 44
21+
// Sample Output
22+
// 11, 21, 31, 41, 42, 32, 22, 12, 13, 23, 33, 43, 44, 34, 24, 14, END
23+
24+
#include<iostream>
25+
using namespace std;
26+
int main() {
27+
int m,n;
28+
cin>>m>>n;
29+
int i,j;
30+
int a[m][n];
31+
for(i=0;i<m;i++)
32+
for(j=0;j<n;j++)
33+
cin>>a[i][j];
34+
for(i=0;i<n;i++){
35+
if(i%2==0)
36+
{
37+
for(j=0;j<m;j++)
38+
cout<<a[j][i]<<", ";
39+
}
40+
else{
41+
for(j=m-1;j>=0;j--)
42+
cout<<a[j][i]<<", ";
43+
}
44+
}
45+
cout<<" END";
46+
47+
return 0;
48+
}

0 commit comments

Comments
 (0)