Program matriks;
uses crt;
var
a,f,k: array [1..100, 1..100] of integer;
b,c,i,j,l,z,a1,b1,c1,d1: longint;
m,n,d,e,g,h,s: byte;
x1,x2,x3:real;
begin
clrscr;
writeln('SELAMAT DATANG P R O G R A M M A T R I K S ');
writeln(' ******************************************'); writeln;
writeln('1. Menghitung Perkalian Matriks');
writeln('2. Menghitung Determinan');
writeln;
writeln(' Pilih Perhitungan 1 atau 2');
writeln(' **************************');
readln(s);
case s of
1: begin
writeln(' PROGRAM PERKALIAN MATRIKS');
writeln(' *************************');writeln;
writeln('Untuk memulai tekan enter !!!');
readln; writeln;
writeln('Masukan data untuk matriks pertama (M1)'); writeln;
write('Jumlah baris untuk matriks pertama: '); readln(b);
write('Jumlah kolom matriks pertama: '); readln(c); writeln;
for d:= 1 to b do
begin
for e:= 1 to c do
begin
write('Masukan baris ke-', d,'kolom ke-',e,': '); readln(a[d,e]);
end;
end; writeln;
writeln('M1: '); writeln;
for d:= 1 to b do
begin
for e:= 1 to c do
begin
write(a[d,e]: 7);
end;writeln;writeln;end;writeln;writeln;
writeln('Masukan data untuk matriks kedua (M2)'); writeln;
write('Berapa banyak baris matriks kedua? '); readln(g);
write('Berapa banyak kolom matriks kedua? '); readln(h); writeln;
for i:= 1 to g do
begin
for j:= 1 to h do
begin
write('Masukan baris ke-', i,'kolom ke',j,': '); readln(f[i,j]);
end;end;writeln;
writeln('M2: '); writeln;
for i:= 1 to g do
begin
for j:= 1 to h do
begin
write (f[i,j]: 7);
end;writeln;writeln;end;writeln;writeln;
writeln('Tekan Enter Untuk Melihat Hasil Operasi dari M1*M2!');
readln;
if c=i then begin
writeln('M1 x M2: ');writeln;
for d:= 1 to b do
begin
for l:= 1 to h do
begin
for e:= 1 to c do
begin
for j:= 1 to h do
begin
for i:= e to g do
begin
k[d,j]:=k[d,j]+a[d,e]*f[i,j];
if c=e then begin
write(k[d,j]:7); end; i:=g;
end;j:=h;end;end;end;writeln;writeln;end;end else
begin
writeln('Maaf? Operasi tidak dapat dilakukan');
writeln('Karena Kolom M1 (',c,'kolom) tidak sama dengan baris M2(',i,'baris)');
end;
end;
2:begin
writeln('Menghitung Determinan Matriks berordo 2x2');
write('Masukan baris, kolom [1,1]= '); readln (a1);
write('Masukan baris, kolom [1,2]= '); readln (b1);
write('Masukan baris, kolom [2,1]= '); readln (c1);
write('Masukan baris, kolom [2,2]= '); readln (d1);
writeln; writeln;
GotoXY(8,17);write(a1);GotoXY(14,17); write(b1);
GotoXY(8,21);write(c1);GotoXY(14,21); write(d1);
writeln;writeln;writeln;writeln;writeln;writeln;writeln;
x1:= a1*d1;
writeln('Nilai a1xd1: ', x1:5:2);
x2:= c1* b1;
writeln('Nilai c1xb1: ',x2:5:2);
x3:= x1-x2;
writeln('Nilai Determinannya: ', x3:5:2);
end;
end;
readln;
end.