Rabu, 16 Desember 2009

Program Perkalian Matriks

program matriks;
uses wincrt;
var
A:array[1..10,1..10] of integer;
B:array[1..7,1..7] of integer;
C:array[1..7,1..7] of integer;
total:array[1..7,1..7] of integer;
i,j,l,m,n,k:integer;
begin
write('berapa jumlah baris matriks 1 ? ');
readln(m);
write('berapa jumlah kolom matriks 1 dan baris matriks 2 ? ');
readln(n);
write('berapa jumlah kolom matirks 2 ? ');
readln(l);
clrscr;

writeln('matriks A');
for i:=1 to m do
for j:=1 to n do
begin
write('A[',i,',',j,'] = ');
readln(A[i,j]);
end;

writeln('matriks B');
for i:=1 to n do
for j:=1 to l do
begin
write('B[',i,',',j,'] = ');
readln(B[i,j]);
end;
clrscr;

writeln('matriks A');
for i:=1 to m do
begin
write('|');
for j:=1 to n do
write(A[i,j]:4);
write('|':4);
writeln;
end;

writeln('matriks B');
for i:=1 to n do
begin
write('|');
for j:=1 to l do
write(B[i,j]:4);
write('|':4);
writeln;
end;writeln;writeln;
for i:=1 to m do
begin
for j:=1 to l do
begin
for k:=1 to n do
begin
c[i,j]:=0;
total[i,j]:=A[i,k]*B[k,j];
c[i,j]:=total[i,j]+C[i,j];
end;
end;
end;
for i:=1 to m do
begin
for j:=1 to l do
write(c[i,j]:4);writeln;
end;
end.

Tidak ada komentar:

Poskan Komentar