-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlec2_WaveFormI.cpp
48 lines (44 loc) Β· 929 Bytes
/
lec2_WaveFormI.cpp
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
47
48
// if even column then print from up to down
// if odd column then print from down to up
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n = 4;
vector<vector<int>> m(n, vector<int>(n, 0));
int count=1;
cout<<"Given Matrix"<<endl;
for(int i = 0;i<n;i++)
{
for(int j = 0 ; j<n;j++)
{
m[i][j] = count++;
cout<<m[i][j]<<" ";
}
cout<<endl;
}
cout<<"In wave form "<<endl;
int col = m.size();
int row = m[0].size();
for(int j = 0 ;j<col;j++)
{
if(j%2==0)
{
for(int i = 0 ; i<row;i++)
{
cout<<m[i][j]<<" ";
}
cout<<endl;
}
else
{
for(int i = row -1;i>=0;i--)
{
cout<<m[i][j]<<" ";
}
cout<<endl;
}
}
return 0;
}