Program Perkalian Matrix (Turbo Pascal)

Saya tuliskan skrip program perkalian matrix menggunakan turbo pascal.
Selamat mencoba, selamat belajar dan jangan menyerah!

Program Perkalian_Matriks;
uses wincrt;
var
   a,f,k:array[1..10,1..10] of integer;
   b,c,i,j,l,z:longint; m,n,d,e,g,h:byte;
begin clrscr;
{write(' Program Perkalian 2 Matriks');readln;writeln;}
writeln('Masukkan data untuk matriks pertama (M1)');
write('banyaknya baris matriks pertama: '); readln(b);
write('banyaknya kolom matriks pertama: '); readln(c);
    for d:= 1 to b do
    begin
    for e:= 1 to c do
       begin
       write('entri baris ke-',d,' kolom ke-',e,': '); readln(a[d,e]);
       end;
    end;
for d:= 1 to b do
    begin
    for e:= 1 to c do
    begin
       write(a[d,e]:7);
    end;writeln;
end;writeln;
writeln('Masukkan data untuk matriks kedua (M2)');
write('berapa banyak baris matriks kedua? '); readln(g);
write('berapa banyak kolom matriks kedua? '); readln(h);
for i:= 1 to g do
    begin
    for j:=1 to h do
    begin
        write('entri baris ke-',i,' kolom ke ',j,': ');  readln(f[i,j]);
    end;
end;
for i:= 1 to g do
    begin
    for j:= 1 to h do
       begin
       write(f[i,j]:7);
    end;writeln;
end;writeln;
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:= l 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;
      end;
end else
begin
writeln('Maaf?! Operasi dari M1 x M2 tidak dapat dilakukan');
writeln('karena kolom M1 (',c,' kolom) tidak sama dengan baris M2 (',i,' baris)');
end;
readln end.

Semoga bermanfaat :)

About these ads

6 Comments

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s