Evo, malo sam se igrao
, ovo bi trebalo da radi (ukoliko opet nisam
nešto prevideo
).
Code:
program Determinanta;
var
n, sign: integer;
det, err : real;
mat : array [1..100, 1..100] of real;
procedure input;
var
i, j : integer;
begin
write('Unesi n: ');
read(n);
for i:= 1 to n do
for j:= 1 to n do
begin
write('Unesi element [', i, ',', j, ']: ');
read(mat[i,j]);
end;
end;
procedure swap_rows(a, b : integer);
var
tmp : real;
i : integer;
begin
for i:= a to n do
begin
tmp:= mat[a,i];
mat[a,i]:= mat[b,i];
mat[b,i]:= tmp;
end;
sign:= sign * (-1);
end;
procedure eliminate(a, b : integer);
var
d : real;
i : integer;
begin
d:= mat[b,a] / mat[a,a];
for i:= a to n do
mat[b,i]:= mat[b,i] - d*mat[a,i];
end;
procedure gauss;
var
i, j : integer;
begin
for i:= 1 to n-1 do
begin
j:= i+1;
while (abs(mat[i,i]) < err) do
begin
swap_rows(i, j);
Inc(j);
if (j > n) then break;
end;
if (j <= n) then for j:= i+1 to n do eliminate(i, j);
end;
for i:= 1 to n do
det:= det * mat[i,i];
end;
Begin
det:= 1.0;
sign:= 1;
err:= 0.000001;
input();
gauss();
writeln('Determinanta je: ', det*sign);
End.