Popular Post

Posted by : Unknown Jumat, 22 November 2013

program operasi_matriks;
uses wincrt;                    
type matrix=array[1..20,1..20] of integer;
var A,B,hasil:matrix;
    v,w,u,ba,ka,bb,kb:integer;
    pil:1..9;

procedure isi(var X:matrix;p,q:byte);
begin
for v:=1 to p do
begin
     for w:=1 to q do
     begin
     writeln('isi elemen ke [',v,',',w,'] ');
     readln(X[v,w]);
     end;
end;
end;

procedure tampil(var X:matrix;p,q:byte);
begin
for v:=1 to p do
begin
     for w:=1 to q do write(X[v,w]:6);
     writeln;
end;
end;


procedure kali(var X,Y:matrix;p,q:integer);
begin
for v:=1 to p do
for w:=1 to q do
     begin
          hasil[v,w]:=0;
          for u:=1 to p do
          begin
          hasil[v,w]:=hasil[v,w]+X[v,u]*Y[u,w];
          end;
     end;
end;

procedure jumlah(var X,Y:matrix;p,q:byte);
begin
for v:=1 to p do
begin
     for w:=1 to q do hasil[v,w]:=X[v,w]+Y[v,w];
end;
end;

procedure kurang(var X,Y:matrix;p,q:byte);
begin
for v:=1 to p do
begin
     for w:=1 to q do hasil[v,w]:=X[v,w]-Y[v,w];
end;
end;

procedure transpos(var X:matrix;p,q:byte);
begin
for v:=1 to p do
begin
     for w:=1 to q do write(X[w,v]:6);
     writeln;
end;
end;

{program utama}
begin
repeat
begin
clrscr;
writeln('MENU PILIHAN OPERASI MATRIX');
writeln('-------------------------');
writeln('1. Isi matrix A');
writeln('2. Isi matrix B');
writeln('3. A+B');
writeln('4. A-B');
writeln('5. B-A');
writeln('6. A*B');
writeln('7. A transpose');
writeln('8. B transpose');
writeln('9. selesai');
write('masukkan pilihan anda <1-8> ==> ');readln(pil);
case pil of


1: begin
   writeln('mengisi matrix A');
   write('masukkan baris A       ==> ');readln(ba);
   write('masukan kolom matrix A ==> ');readln(ka);
   isi(A,ba,ka);
   writeln('Matrix a adalah ');
   tampil(A,ba,ka);
   end;
2:begin
   writeln('mengisi matrix B');
   write('masukkan baris B       ==> ');readln(bb);
   write('masukan kolom matrix B ==> ');readln(kb);
   isi(B,bb,kb);
   writeln('Matrix B adalah ');
   tampil(B,bb,kb);
   end;
3: begin
   if (ba=bb) and (ka=kb) then
      begin
        writeln('matrix A = ');
        tampil (A,ba,ka);
        writeln('matrix B = ');
        tampil (B,bb,kb);
        writeln('hasil A+B adalah ');
        jumlah(A,B,ba,ka);
        tampil(hasil,ba,ka);
      end
   else writeln('operasi A+B tidak bisa dihitung karena ordo berbeda');
   end;
4: begin
   if (ba=bb) and (ka=kb) then
      begin
        writeln('matrix A = ');
        tampil (A,ba,ka);
        writeln('matrix B = ');
        tampil (B,bb,kb);
        writeln('hasil A-B adalah ');
        kurang(A,B,ba,ka);
        tampil(hasil,ba,ka);
      end
   else writeln('operasi A-B tidak bisa dihitung karena ordo berbeda');
   end;
5: begin
   if (ba=bb) and (ka=kb) then
      begin
        writeln('matrix A = ');
        tampil (A,ba,ka);
        writeln('matrix B = ');
        tampil (B,bb,kb);
        writeln('hasil B-A adalah ');
        kurang(B,A,ba,ka);
        tampil(hasil,ba,ka);
      end
   else writeln('operasi B-A tidak bisa dihitung karena ordo berbeda');
   end;
6: begin
   writeln('matrix A = ');
   tampil (A,ba,ka);
   writeln('matrix B = ');
   tampil (B,bb,kb);
   writeln('hasil B*A adalah ');
   kali(A,B,ba,ka);
   tampil(hasil,ba,ka);
   end;
7: begin
   writeln('Matrix A');
   tampil(A,ba,ka);
   writeln('Transpose Matrix A');
   transpos(A,ka,ba);
   end;
8: begin
   writeln('Matrix B');
   tampil(B,bb,kb);
   writeln('Transpose Matrix B');
   transpos(B,kb,bb);
   end;
9:writeln('terima kasih sudah berpartisipasi');
end;
readln;
end
until(pil=9);
end.

Leave a Reply

saat berkomentar harap di jaga perkataan anda
komentar yang berbau SARA atau sebalik nya akan saya hapus/di spam

Subscribe to Posts | Subscribe to Comments

- Copyright © ARDIANSYAH LENGE - Date A Live - Powered by Blogger - Designed by ardiansyah lenge -