CONTOH 1
program
perkalian_matrix;
uses
crt;
var
a,b,c : array [1..50,1..50] of integer;
i,j,k,x,y,z : integer;
begin
clrscr;
writeln('Ukuran matrix A');
write('Baris : ');
readln(x);
write('Kolom : ');
readln(y);
writeln;
writeln;
writeln('Ukuran matrix B');
writeln('Baris : ',y);
write('Kolom : ');
readln(z);
for i:=1 to x do
for j:=1 to y do
begin
write('Elemen A[',i,',',j,'] :
');
readln(a[i,j]);
end;
writeln;
for i:=1 to y do
for j:=1 to z do
begin
write('Elemen
B[',i,',',j,'] : ');
readln(b[i,j]);
end;
for i:=1 to x do
for j:=1 to z do
for k:=1 to y do
c[i,j] := c[i,j] +
a[i,k]*b[k,j];
writeln;
writeln;
writeln('Hasil dari
perkalian Matrix A dengan Matrix B adalah : ');
Writeln;
for i:=1 to x do
begin
for j:=1 to z do
write(c[i,j],' ');
writeln;
end;
writeln;
readln;
end.
CONTOH 2
program
matrik;
uses
crt;
type
data = array[1..10,1..10] of integer;
var
matrikI,matrikII,hasil : data;
baris,kolom : integer;
var i,j,z : integer;
begin
writeln('Penentuan ORDO MATRIK I');
write('Masukan banyak baris matrik I =
');readln(baris);
write('Masukan banyak kolom matrik I =
');readln(kolom);
for i:=1 to baris do
for j:=1 to kolom do
begin
gotoxy(j*10,i*5);
read(matrikI[i,j]);
end;
clrscr;
writeln('Penentuan ORDO MATRIK II');
write('Masukan banyak baris matrik II =
');readln(baris);
write('Masukan banyak kolom matrik II =
');readln(kolom);
for i:=1 to baris do
for j:=1 to kolom do
begin
gotoxy(j*10,i*5);
readln(matrikII[i,j]);
end;
begin
for i:=1 to baris do
for j:=1 to kolom do
begin
hasil[i,j]:=0;
for z:=1 to baris do
hasil[i,j]:=hasil[i,j]+matrikI[i,z]*matrikII[z,j];
end;
clrscr;
writeln('Hasil Perkalian MATRIK');
for i:=1 to baris do
for j:=1 to kolom do
begin
gotoxy(j*10,i*5);
write(hasil[i,j]);
end;
end;
end.
ALGORITMA KALI
MATRIK
Begin
a,b,c : array [1..50,1..50] of integer;
i,j,k,x,y,z
: integer;
begin
for i:=1 to x do
for j:=1 to y do
begin
write('Elemen A[',i,',',j,'] :
');
readln(a[i,j]);
end;
end;
begin
for i:=1 to y do
for j:=1 to z do
begin
write('Elemen
B[',i,',',j,'] : ');
readln(b[i,j]);
end;
end;
begin
for
i:=1 to x do
for j:=1 to z do
for k:=1 to y do
c[i,j] := c[i,j] + a[i,k]*b[k,j];
end;
for i:=1 to x do
begin
for j:=1 to z do
write(c[i,j],' ');
writeln;
end;
writeln;
readln;
end.
Tidak ada komentar:
Posting Komentar