forked from BitsPleaseMSI/BitsPlease-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
35.c
55 lines (50 loc) · 1.01 KB
/
35.c
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
#include <stdio.h>
#include <conio.h>
#include <math.h>
#define MAXSIZE 5 //size of matrix can be changed from here
void Enter(int A[][MAXSIZE], int);
int detA(int A[][MAXSIZE], int);
void Minor(int A[][MAXSIZE], int M[][MAXSIZE], int, int, int);
void main() {
int A[MAXSIZE][MAXSIZE], size, det;
scanf("%d", &size);
Enter(A, size);
det = detA(A, size);
printf("%d", det);
getch();
}
void Enter(int A[][MAXSIZE], int size) {
int i, j;
for (i=0; i<size; i++) {
for (j=0; j<size; j++) {
scanf("%d", &A[i][j]);
}
}
}
int detA(int A[][MAXSIZE], int size) {
int det = 0, i;
int M[size-1][size-1];
if (size==1) return A[0][0];
else {
for (i=0; i<size; i++) {
Minor(A, M, 0, i, size);
det = det + (pow(-1, i) * A[0][i] * detA(M, size-1));
}
return det;
}
}
void Minor(int A[][MAXSIZE], int M[][MAXSIZE], int I, int J, int size) {
int i, j, k=0, l=0;
for (i=0; i<size; i++) {
if (i!=I) {
for (j=0; j<size; j++) {
if (j!=J) {
M[k][l] = A[i][j];
l++;
}
}
l=0;
k++;
}
}
}