-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprint_matrix.cpp
More file actions
40 lines (33 loc) · 843 Bytes
/
print_matrix.cpp
File metadata and controls
40 lines (33 loc) · 843 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
#include <iostream>
#include <vector>
int main(){
std::vector<std::vector<int>> v(8, std::vector<int>(8, 0));
for(int i = 0; i < 8; i++){
for(int j = 0; j < 8; j++){
v[i][j]= (i+1)*(j+1);
}
}
// printing the matrix
for(int i = 0; i < 8; i++){
for(int j = 0; j < 8; j++){
std::cout << v[i][j] << '\t';
}
std::cout << '\n';
}
int row, col;
int rowCount = v.size();
int columnCount = v[0].size();
for(int k = 0; k < rowCount; k++){
for(row = k, col = 0; row >= 0 && col <= columnCount; row --, col++){
std::cout << v[row][col] << '\t';
}
std::cout << '\n';
}
for(int k = 0; k < rowCount; k++){
for(row = rowCount -1, col = k; row >= 0 && col <= columnCount; row --, col++){
std::cout << v[row][col] << '\t';
}
std::cout << '\n';
}
return 0;
}