Minggu, 22 April 2012

Program Mengalikan_2_Matriks; ( Algoritma dan Pemograman )


Program Mengalikan_2_Matriks;
uses crt;
type
  matriks = array[1..50,1..50] of integer;
var
  A,B,C  : matriks;
  x,y,z  : integer;

procedure isi_matriks(var x,y,z: integer; var A,B : matriks);
var
i,j : integer;
begin
  gotoxy(20,1);writeln('Perkalian 2 Buah Matriks');
  gotoxy(20,2);writeln('------------------------');
  window(2,3,23,7);textbackground(2);clrscr;
  gotoxy(2,1);writeln('    Matriks A     ');
  gotoxy(2,2);writeln('-------------------');
  gotoxy(2,3);write('Banyaknya Baris : ');readln(x);
  gotoxy(2,4);write('Banyaknya Kolom : ');readln(y);
  window(36,3,57,7);textbackground(2);clrscr;
  gotoxy(2,1);writeln('    Matriks B     ');
  gotoxy(2,2);writeln('-------------------');
  gotoxy(2,3);writeln('Banyaknya Baris : ',x);
  gotoxy(2,4);write('Banyaknya Kolom : ');readln(z);

  window(2,9,23,17);textbackground(blue);clrscr;
  textcolor(black);
  gotoxy(7,1);write('Matriks A');
  gotoxy(7,2);write('=========');
  for i := 1 to x do
  begin
    for j := 1 to y do
      begin
        gotoxy(j*5,i+2);readln(A[i,j]);
      end;
    end;
   window(36,9,57,17);textbackground(blue);clrscr;
  textcolor(black);
  gotoxy(7,1);write('Matriks B');
  gotoxy(7,2);write('=========');
  for i := 1 to y do
  begin
    for j := 1 to z do
      begin
        gotoxy(j*5,i+2);readln(B[i,j]);
      end;
    end;
end;
procedure jumlah_matriks (x,y : integer; A,B : matriks; var C : matriks);
var
  h,i,j : integer;
begin
for i := 1 to x do
  begin
      for j := 1 to y do
      begin
         for x := 1 to z do
         begin
           C[i,j]:=0;
           for h:=1 to y do
           begin
           C[i,j] := c[i,j] + (A[i,h] * B[h,j]);
           end;
         end;
      end;
   end;
end;
procedure Tampil_hasil(x,y : integer; C : matriks);
var
i,j : integer;
begin
  window(18,19,50,27);textbackground(5);clrscr;
  textcolor(15);
  gotoxy(11,1);write('Matriks Hasil');
  gotoxy(11,2);write('=============');
  for i := 1 to x do
  begin
    for j := 1 to y do
      begin
      gotoxy(j*5,i+2);write(C[i,j]);
      end;
      end;
  end;

begin
  Isi_matriks(x,y,z,A,B);
  jumlah_matriks(x,y,A,B,C);
  Tampil_hasil(x,z,C);
  readln;
end.

Tidak ada komentar:

Posting Komentar