Dalam perkalian matrik sering kita temui banyak kondisi disini akan saya bahas contoh sedikit tentang perkalian matrik.
misal contoh program matrik_dua_dimensi;
uses wincrt;
const
jbaris=2;
jkolom=2;
type
matrik = array [1..jbaris,1..jkolom] of integer;
var
A,B,C: matrik;
j,k : integer;
procedure baca_matrik ( var A:matrik; jbaris,jkolom: integer);
begin
{mengisi matrik A}
writeln(‘Matrik A’);
for j:= 1 to jbaris do begin
for k:= 1 to jkolom do begin
write(‘A[',j,',',k,']=’); readln(A[j,k]);
end;
writeln;
end;
writeln;
(*mengisi matrik B *)
writeln(‘Matrik B’);
for j:= 1 to jbaris do begin
for k:= 1 to jkolom do begin
write(‘B[',J,',',K,']=’);readln(b[j,k]);
end;
writeln;
end;
end;
procedure cetak_matrik ( A,B,C:matrik; jbaris,jkolom:integer);
begin
writeln (‘Hasil penjumlahan matrik A dan B ‘);
for j:= 1 to jbaris do begin
for k:= 1 to jkolom do begin
c[j,k]:= a[j,k]+b[j,k];
writeln(‘C[',j,',',k,']=’,c[j,k]);
end;
writeln;
end;
end;
begin
writeln (‘ penjumlahan matrik ‘);
baca_matrik (a,jbaris,jkolom);
cetak_matrik ( a,b,b,jbaris,jkolom);
end.
misal contoh program matrik_dua_dimensi;
uses wincrt;
const
jbaris=2;
jkolom=2;
type
matrik = array [1..jbaris,1..jkolom] of integer;
var
A,B,C: matrik;
j,k : integer;
procedure baca_matrik ( var A:matrik; jbaris,jkolom: integer);
begin
{mengisi matrik A}
writeln(‘Matrik A’);
for j:= 1 to jbaris do begin
for k:= 1 to jkolom do begin
write(‘A[',j,',',k,']=’); readln(A[j,k]);
end;
writeln;
end;
writeln;
(*mengisi matrik B *)
writeln(‘Matrik B’);
for j:= 1 to jbaris do begin
for k:= 1 to jkolom do begin
write(‘B[',J,',',K,']=’);readln(b[j,k]);
end;
writeln;
end;
end;
procedure cetak_matrik ( A,B,C:matrik; jbaris,jkolom:integer);
begin
writeln (‘Hasil penjumlahan matrik A dan B ‘);
for j:= 1 to jbaris do begin
for k:= 1 to jkolom do begin
c[j,k]:= a[j,k]+b[j,k];
writeln(‘C[',j,',',k,']=’,c[j,k]);
end;
writeln;
end;
end;
begin
writeln (‘ penjumlahan matrik ‘);
baca_matrik (a,jbaris,jkolom);
cetak_matrik ( a,b,b,jbaris,jkolom);
end.
0 Comments