-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeterminant.cpp
More file actions
62 lines (47 loc) · 1.55 KB
/
Copy pathdeterminant.cpp
File metadata and controls
62 lines (47 loc) · 1.55 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <iostream>
#include <vector>
long long determinant(std::vector<std::vector<long long> > m) {
// TODO: Return the determinant of the square matrix passed in
int result;
if(m.size() == 1) {
return m[0][0];
}
if(m.size() == 2) {
return (m[0][0] * m[1][1]) - (m[0][1] * m[1][0]);
}
//reduce matrix
std::vector<std::vector<long long>> temp((m.size() - 1), std::vector<long long>(m[0].size() - 1));
for(int col = 0; col < temp.size(); col++){
}
return 0;
}
void init_matrix(std::vector<std::vector<long long>> &matrix) {
for (int i = 0; i < matrix.size(); i++) {
for (int j = 0; j < matrix[0].size(); j++) {
matrix[i][j] = i + j + 1 * 2; //initialize test values
}
}
}
void print_matrix(std::vector<std::vector<long long>> matrix) {
for(const auto &row : matrix) {
for(int num : row) {
std::cout << num << " ";
}
std::cout << "\n\n";
}
}
int main() {
std::vector<std::vector<long long>> matrix_a(2,std::vector<long long>(2));
std::vector<std::vector<long long>> matrix_b(3,std::vector<long long>(3));
std::vector<std::vector<long long>> matrix_c(4,std::vector<long long>(4));
init_matrix(matrix_a);
init_matrix(matrix_b);
init_matrix(matrix_c);
print_matrix(matrix_a);
std::cout << determinant(matrix_a) << std::endl;
print_matrix(matrix_b);
std::cout << determinant(matrix_b) << std::endl;
print_matrix(matrix_c);
std::cout << determinant(matrix_c) << std::endl;
return 0;
}