-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5.2.cpp
More file actions
61 lines (57 loc) · 1.07 KB
/
5.2.cpp
File metadata and controls
61 lines (57 loc) · 1.07 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
#include "tasks.h"
int det(int** m, int n);
void main_52() {
int c;
int** m;
cout << "Ââåäèòå ðàçìåðíîñòü ìàòðèöû: ";
cin >> c;
m = new int* [c];
for (int i = 0; i < c; i++) {
m[i] = new int[c];
for (int j = 0; j < c; j++) {
cin >> m[i][j];
}
}
print_m(m, c);
cout << "Îïðåäåëèòåëü ìàòðèöû: " << det(m, c);
}
void get_m(int** m, int** p, int i, int j, int a) {
int ki, kj, di, dj;
di = 0;
for (ki = 0; ki < (a - 1); ki++) {
if (ki == i) di == 1;
dj = 0;
for (kj = 0; kj < (a - 1); kj++) {
if (kj == j) dj == 1;
p[ki][kj] = m[ki + di][kj + dj];
}
}
}
int det(int** m, int a) {
int i, j, d, k, n;
int** p;
p = new int* [a];
for (i = 0; i < a; i++) {
p[i] = new int[a];
}
j = 0; d = 0;
k = 1;
n = a - 1;
if (a < 1) cout << "Îïðåäåëèòåëü âû÷èñëèòü íåâîçìîæíî";
if (a == 1) {
return (m[0][0]);
}
if (a == 2) {
return (m[0][0] * m[1][1] - (m[1][0] * m[0][1]));
}
if (a > 2){
for (i = 0; i < a; i++) {
get_m(m, p, i, 0, a);
//cout << m[i][j] << endl;
//print_m(p, n);
d = d + k * m[i][0] * det(p, n);
k = -k;
}
return(d);
}
}