-4

I'm trying to make a program to find the determinant of a matrix like this :

program determinan;
uses crt;
type
        arr=array of array of real;
var
        mat:arr;
        uk:byte;
procedure ukuran(var x:arr;var n:byte);
        begin
                write('Masukkan ukuran matriks : ');readln(n);
                setlength(x,n+1,n+1);
        end;
procedure masuk(var x:arr;n:byte);
        var
                i,j:byte;
        begin
                writeln('Masukkan elemen matriks : ');
                for i:= 1 to n do
                for j:= 1 to n do
                begin
                        write('E(',i,',',j,'):');
                        read(x[i,j]);
                end;
        end;
procedure tulis(x:arr;n:byte;nama:string);
        var
                i,j:byte;
        begin
                writeln('Matriks ',nama,' : ');
                for i:= 1 to n do
                begin
                        for j:=1 to n do
                                write(x[i,j]:0:0,' ');
                        writeln;
                end;
        end;
procedure segitiga(var x:arr;n:byte);
        var
                i,j,k:byte;
                nano :real;
        begin
                for i:=1 to n-1 do
                for j:=i+1 to n do
                begin
                        nano:=x[j,i]/x[i,i];
                        for k:=i to n do x[j,k]:=x[j,k]-nano*x[i,k];
                end;
        end;
function determinan(x:arr;n:byte):real;
        var
                i:byte;
        begin
                determinan:=1;
                for i:=1 to n do
                        determinan:=determinan*x[i,i];
        end;
begin
        clrscr;
        writeln('-----------------------------');
        writeln('Program Menghitung Determinan');
        writeln('-----------------------------');
        ukuran(mat,uk);
        masuk(mat,uk);writeln;
        tulis(mat,uk,'asal');writeln;
        segitiga(mat,uk);
        tulis(mat,uk,'segitiga atas');writeln;
        writeln('Determinan : ',determinan(mat,uk):0:0);
        readkey;
end.

But, if I input with 3x3 matrix with elements (1,1,1;1,1,1;1,1,1) it will be exit with error 207. It's also happened if I try to input matrix with same colum element. But, it not happened in 2x2 matrix. Please, tell me what is the reason of such behavior because I can't fund it

syh
  • 7
  • 1
  • 2
    Use the debugger and trace the point of error. – LU RD Jun 12 '21 at 17:48
  • In case you compiled it with [FPC then your runtime error #207 means "_invalid floating point operation_"](https://www.freepascal.org/docs-html/user/userap4.html). Reading the documentation is a must. – AmigoJack Jun 12 '21 at 17:57
  • 2
    Also, if you want us to help you, surely it is in your best interest to make it as easy for us as possible to do so. This would include translating the words "ukuran", "masuk", "tulis", "segitiga", etc. into English! – Andreas Rejbrand Jun 12 '21 at 18:10
  • 4
    `for i:= 1 to n...` - but you use dynamic arays, they are zero-based – MBo Jun 12 '21 at 18:20
  • Please don't tag spam. You're clearly not trying to compile and run this code under standard Pascal, Delphi, and Free Pascal at the same time. Add only the tag that actually applies to your post. It's a waste of both your time and ours when you use misleading tags. Remove the ones that do not apply specifically to your post. – Ken White Jun 14 '21 at 03:36

1 Answers1

0

This line:
nano:=x[j,i]/x[i,i];
x[i,i] may equal to zero,in pascal if you divide a number by 0 , it will return error 207
Your code should be this:
if (x[i,i] <> 0) then nano:=x[j,i]/x[i,i];