Wednesday, March 23, 2011

Pascal - Program Perkalian Matriks Ordo n x m dengan m x p

program Kali_Matrix;
uses wincrt;
var
   a,b,c : array [1..50,1..50] of integer;
   i,j,k,n,m,p : integer;
begin
     clrscr;
     writeln('Ukuran matrix A');
     write('Baris : '); readln(n);
     write('Kolom : '); readln(m);
     writeln;
     writeln;
     writeln('Ukuran matrix B');
     writeln('Baris : ',m);
     write('Kolom : '); readln(p);
     writeln;
     for i:=1 to n do
     for j:=1 to m do
     begin
          write('Elemen A[',i,',',j,'] : ');
          readln(a[i,j]);
     end;
     writeln;
     for i:=1 to m do
     for j:=1 to p do
     begin
          write('Elemen B[',i,',',j,'] : ');
          readln(b[i,j]);
     end;
     for i:=1 to n do
     for j:=1 to p do
     for k:=1 to m 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 n do
     begin
          for j:=1 to p do
          write(c[i,j],' ');
     writeln;
     end;
     writeln;
     readln;
end.

Bila ada yang kurang harap di maklumi karena saya juga masih belajar,,,

0 comments:

Post a Comment