-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11-31.cpp
43 lines (37 loc) · 840 Bytes
/
11-31.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
#include "kmatrix.hpp"
#include <iostream>
using namespace std;
template<class Iter_T>
void outputRowOrColumn(Iter_T iter, int n) {
for (int i=0; i < n; ++i) {
cout << iter[i] << " ";
}
cout << endl;
}
template<class Matrix_T>
void initializeMatrix(Matrix_T& m) {
int k = 0;
for (int i=0; i < m.rows( ); ++i) {
for (int j=0; j < m.cols( ); ++j) {
m[i][j] = k++;
}
}
}
template<class Matrix_T>
void outputMatrix(Matrix_T& m) {
for (int i=0; i < m.rows( ); ++i) {
cout << "Row " << i << " = ";
outputRowOrColumn(m.row(i), m.cols( ));
}
for (int i=0; i < m.cols( ); ++i) {
cout << "Column " << i << " = ";
outputRowOrColumn(m.col(i), m.rows( ));
}
}
int main( )
{
kmatrix<int, 2, 4> m;
initializeMatrix(m);
m *= 2;
outputMatrix(m);
}