Okii's blog ^^ just a simple blog ...

Okii's blog ^^ just a simple blog ...

Kamis, 01 Desember 2011

Penjumlahan dan Perkalian Matriks Ordo 2x2

program matrik;
uses crt;

var mat1, mat2, jml, kali : array[1..2,1..2] of integer;
    i, j, k : integer;

begin
    clrscr;
    writeln('Input Matrik 1');
    writeln('--------------');
    writeln;
    for i := 1 to 2 do
    begin
       for j := 1 to 2 do
       begin
          write('[',i,',',j,'] = ');
          readln(mat1[i,j]);
       end;
    end;

    writeln;
    writeln('Input Matrik 2');
    writeln('--------------');
    writeln;
    for i := 1 to 2 do
    begin
       for j := 1 to 2 do
       begin
          write('[',i,',',j,'] = ');
          readln(mat2[i,j]);
       end;
    end;

    writeln;
    writeln('Tekan enter untuk melihat data...');
    readln;

    clrscr;
    writeln('Matrik 1');
    writeln('--------');
    for i := 1 to 2 do
    begin
       for j := 1 to 2 do
       begin
          write(mat1[i,j],'  ');
       end;
       writeln;
    end;

    writeln;
    writeln('Matrik 2');
    writeln('--------');
    for i := 1 to 2 do
    begin
       for j := 1 to 2 do
       begin
          write(mat2[i,j],'  ');
       end;
       writeln;
    end;

    writeln;
    writeln('Hasil Penjumlahan Matrik Adalah');
    writeln('-------------------------------');
    writeln;
    for i := 1 to 2 do
    begin
       for j := 1 to 2 do
       begin
         jml[i,j]:=mat1[i,j] + mat2[i,j];
         write(jml[i,j],'  ');
       end;
       writeln;
    end;

    writeln;
    writeln;
    writeln('Hasil Perkalian Matrik Adalah');
    writeln('-----------------------------');
    writeln;
    for i := 1 to 2 do
    begin
       for j := 1 to 2 do
       begin
         kali[i,j] := 0;
         for k := 1 to 2 do
         kali[i,j] := kali[i,j] + mat1[i,k] * mat2[k,j];
         write(kali[i,j],'  ');
       end;
       writeln;
    end;
    readln;
end.