Rabu, 18 Januari 2012

Kode Program untuk Menghitung Determinan Matriks ordo 2x2 dan 3x3 dengan aplikasi Pascal

 program determinanmatrix;
uses crt;
type t = object
data1 : array [1..2,1..2] of integer;
data2 : array [1..3,1..3] of integer;
procedure input;
procedure deter;
procedure tampil;
end;

var m :t;
x, y, z, pil, det1, det2 : integer;

procedure t.input;
begin
clrscr;
writeln ('Input Matrix Berordo 2x2');
for x:= 1 to 2 do
begin
for y:= 1 to 2 do
begin
write ('Elemen [',x,',',y,']: ');
readln (data1[x,y]);
end;
end;
gotoxy (25,1); writeln('Input Matrix Berordo 3x3');z:=2;
for x:= 1 to 3 do
begin
for y:= 1 to 3 do
begin
gotoxy (25,z);inc (z);
write ('Elemen [',x,',',y,']: ');
readln (data2[x,y]);
end;
end;
end;

procedure t.tampil;
begin
writeln;
writeln(' Matrix Berordo 2x2 ');
writeln (data1[1,1]:5,data1[1,2]:5);
writeln (data1[2,1]:5,data1[2,2]:5);
gotoxy (25,19);writeln(' Matrix Berordo 3x3 ');
gotoxy (25,20);writeln (data2[1,1]:5,data2[1,2]:5,data2[1,3]:5);
gotoxy (25,21);writeln (data2[2,1]:5,data2[2,2]:5,data2[2,3]:5);
gotoxy (25,22);writeln (data2[3,1]:5,data2[3,2]:5,data2[3,3]:5);
readln;
end;

procedure t.deter;
begin
det1 := (data1[1,1]*data1[2,2])-(data1[1,2]*data1[2,1]);
det2 := ((data2[1,1]*data2[2,2]*data2[3,3])+(data2[1,2]*data2[2,3]*data2[3,1])+(data2[1,3]*data2[2,1]*data2[3,2]))-((data2[3,1]*data2[2,2]*data2[1,3])+(data2[3,2]*data2[2,3]*data2[1,1])+(data2[3,3]*data2[2,1]*data2[1,2]));
writeln;
writeln ('Determinan Matrix Berordo 2x2 = ',det1);
writeln ('Determinan Matrix Berordo 3x3 = ',det2);
readln;
end;

begin
repeat
clrscr;
gotoxy(27,1);writeln ('MENU MATRIK');
gotoxy(27,2);writeln ('1. Input Matrix');
gotoxy(27,3);writeln ('2. Determinan Matrix');
gotoxy(27,4);writeln ('3. Keluar');
gotoxy(27,7);write ('Pilihannya adalah: ');
readln(pil);
case pil of
1 : begin
m.input;
m.tampil;
end;
2 : m.deter;
end;
until (pil)=3
end.