forked from dscgecbsp/Hacktoberfest-2021
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwave_array.cpp
More file actions
46 lines (36 loc) · 683 Bytes
/
wave_array.cpp
File metadata and controls
46 lines (36 loc) · 683 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include<iostream>
using namespace std;
/*
Wave array
Input 3 4
1 2 3 4
5 6 7 8
9 10 11 12
Output : 1 5 9 10 6 2 3 7 11 12 8 4
*/
void waveArray(int a[][100],int m,int n){
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]<<" ";
}
}
}
}
int main(){
int a[100][100];
int n,m;
cin>>m>>n;
//input array
for(int i=0;i<m;++i){
for(int j=0;j<n;++j){
cin>>a[i][j];
}
}
waveArray(a,m,n);
return 0;
}