-
Notifications
You must be signed in to change notification settings - Fork 0
/
AnyMatrixDeterminantCalculator.c
111 lines (110 loc) · 1.92 KB
/
AnyMatrixDeterminantCalculator.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int* take (int ,int *);
void show (int , int *);
int grandsome=0;
int calcule(int ,int *,int );
int bestline( int ,int * );
int main()
{
int p=0,MAX,i;
printf("This programe can calculate the determenent of any matrix n*n\n");
printf("Give matrix dimension : n=");
scanf("%d",&MAX);
MAX=MAX*MAX;
int /*tab[MAX]*/b=0;
int n=MAX;
int*tab;
tab = (int*)malloc(n * sizeof(int));
take (MAX,tab);/*take tableau input*/
show(MAX,tab);/*show the matrix*/
b=calcule1(MAX,tab,p);
printf("Its determenent is :%d\n",b );
return 0;
}
int* take (int MAX,int *tab)
{
int i,j;
for (i=0;i<MAX;i++)
{
j=i/sqrt(MAX);
scanf("%d",&tab[i]);
}
return(tab);
}
void show(int MAX,int *tab)
{
int j,i;
printf("Your matrix is :\n");
for ( i = 0; i < MAX; i++)
{
printf("%4d ",tab[i] );
for(j=sqrt(MAX)-1;j<MAX;j+=sqrt(MAX))
{
if(i==j)
printf("\n");
}
}
}
int calcule1(int i,int *tabprim,int c)
{
int d=1;
for(c=0;c<sqrt(i);c++)
{
grandsome+=d*tabprim[c]*calcule(i,tabprim,c);
d=-d;
}
return(grandsome);
}
int calcule(int i,int *tabprim,int c)
{
int r=0,lastcalcule(int *tab1);
int* takefrom(int i,int *tabprim,int *tab1,int r,int c);
r=(sqrt(i)-1)*(sqrt(i)-1);
int tab1[r];
takefrom(i,tabprim,tab1,r,c);
if(r>4)
{
int p;
int d=1;
for(p=0;p<sqrt(r);p++)
{
grandsome+=d*tab1[c]*calcule(r,tab1,p);
d=-d;
}
return(grandsome);
}
else
{
return (lastcalcule(tab1));
}
}
int* takefrom(int i,int *tabprim,int *tab1,int r,int c)
{
int t,j,d=1;
c=c+(int)sqrt(i);
for(j=(int)sqrt(i),t=0;j<i,t<r;j++,t++)
{
if(j!=c)
{
tab1[t]=tabprim[j];
}
else
{
t--;
c=c+(int)sqrt(i);
}
}
return(tab1);
}
int lastcalcule(int *tab1)
{
int some,a,b,c,d;
a=tab1[1];
b=tab1[2];
c=tab1[3];
d=tab1[0];
some=d*c-a*b;
return(some);
}