Code:
Det := Det + sgn*Compute(k,1,depth-1,Mat2);
Det := Det + sgn*Compute(k,1,depth-1,Mat2);
a depth je 2, pravilno izracuna taj deo i zatim po izlasku iz procedure, umesto da predje na sledeci red, javi mi SIGFPE Arithmetic Exception... Zasto?
Inace, radim u Free Pascalu...
Code:
Program Domaci;
Const
MaxIndex = 100;
Type
Matrica = Array[1..MaxIndex,1..MaxIndex] Of Real;
Var
Mat1 : Matrica;
n : Integer;
Det : Real;
Procedure Load;
Var
i,j : Integer;
Fin : Text;
Begin
Assign(Fin,'Det.dat');
Reset(Fin);
Read (n);
Det := 0;
Writeln;
For i:=1 to n Do
For j:=1 to n Do Begin
Read(Fin,Mat1[i,j]);
End;
Close(Fin);
End;
Procedure Draw;
Var
i,j : integer;
Begin
For i:=1 to n Do Begin
For j:=1 to n Do Begin
Write(Mat1[i,j]:0:0,'|');
End;
Writeln;
End;
End;
Function Compute(a,b,depth : Integer;Mat : Matrica) : Real;
var
m,l,k,i,j : Integer;
NextRow : Boolean;
a1,sgn : Integer;
Mat2 : Matrica;
Begin
If depth=2 then Begin
Det:=Det+Mat[a,b]*Mat[a+1,b+1]-(Mat[a,b+1]*Mat[a+1,b]);
End
Else Begin
For k := 1 to depth do Begin
m:=1;
l:=1;
For i:=1 to depth Do Begin
NextRow:=False;
For j:=1 to depth Do Begin
If (not(i=k)) and (not(j=b)) Then Begin
Mat2[m,l]:=Mat[i,j];
inc(l);
NextRow:=True;
End;
End;
If NextRow then inc(m);
l:=1;
End;
if (k+b) mod 2 = 0 then sgn:=1 else sgn:=-1;
Det := Det + sgn*Compute(k,1,depth-1,Mat2);
End;
End;
End;
Begin
Load;
Draw;
Writeln;
Compute(1,1,n,Mat1);
Writeln(Det);
End.
Program Domaci;
Const
MaxIndex = 100;
Type
Matrica = Array[1..MaxIndex,1..MaxIndex] Of Real;
Var
Mat1 : Matrica;
n : Integer;
Det : Real;
Procedure Load;
Var
i,j : Integer;
Fin : Text;
Begin
Assign(Fin,'Det.dat');
Reset(Fin);
Read (n);
Det := 0;
Writeln;
For i:=1 to n Do
For j:=1 to n Do Begin
Read(Fin,Mat1[i,j]);
End;
Close(Fin);
End;
Procedure Draw;
Var
i,j : integer;
Begin
For i:=1 to n Do Begin
For j:=1 to n Do Begin
Write(Mat1[i,j]:0:0,'|');
End;
Writeln;
End;
End;
Function Compute(a,b,depth : Integer;Mat : Matrica) : Real;
var
m,l,k,i,j : Integer;
NextRow : Boolean;
a1,sgn : Integer;
Mat2 : Matrica;
Begin
If depth=2 then Begin
Det:=Det+Mat[a,b]*Mat[a+1,b+1]-(Mat[a,b+1]*Mat[a+1,b]);
End
Else Begin
For k := 1 to depth do Begin
m:=1;
l:=1;
For i:=1 to depth Do Begin
NextRow:=False;
For j:=1 to depth Do Begin
If (not(i=k)) and (not(j=b)) Then Begin
Mat2[m,l]:=Mat[i,j];
inc(l);
NextRow:=True;
End;
End;
If NextRow then inc(m);
l:=1;
End;
if (k+b) mod 2 = 0 then sgn:=1 else sgn:=-1;
Det := Det + sgn*Compute(k,1,depth-1,Mat2);
End;
End;
End;
Begin
Load;
Draw;
Writeln;
Compute(1,1,n,Mat1);
Writeln(Det);
End.
Molim vas, pomozite!
Hvala!
And don't be mad at me for crying for humanity,
call it pretensions but I got good intentions,
to keep my sanity, I'm hoping, fuck, there's gotta be
an answer to their strategies and their evil inventions... ~Looptroop
call it pretensions but I got good intentions,
to keep my sanity, I'm hoping, fuck, there's gotta be
an answer to their strategies and their evil inventions... ~Looptroop