Welcome to my blog..!! Enjoy to read and get your knowledge. Hopefully, you can understand it

Senin, 19 Desember 2011

PROGRAM MATRIKS


  • Penjumlahan Matrik
              program matrik_penjumlahan;
              uses wincrt;
              var a,b,c: array[1..10,1..10] of integer;
              i,j,k1,k2,b1,b2,sum,r:integer;

             begin
             write('Masukkan baris Matrik A = ');readln(b1);
             write('Masukkan kolom Matrik A = ');readln(k1);
             write('Masukkan baris Matrik B = ');readln(b2);
             write('Masukkan kolom Matrik B = ');readln(k2);
             for i:=1 to b1 do
             for j:=1 to k1 do
             readln(a[i,j]);
             writeln;
             for i:=1 to b2 do
             for j:=1 to k2 do
             readln(b[i,j]);
             writeln;
             writeln('Matrik A');
             writeln('==================');
             for i:=1 to b1 do
             begin
             for j:=1 to k1 do
             write(a[i,j],' ');
             writeln;
             end;
             writeln;
             writeln('Matrik B');
             writeln('===================');
             for i:=1 to b2 do
            begin
            for j:=1 to k2 do
            write(b[i,j],' ');
            writeln;
            end;
            writeln;
            writeln('Matrik A*B');
            writeln('================');
            for i:=1 to b1 do
            begin
            for j:=1 to k2 do
            begin
            sum:=0;
            for r:=1 to k1 do
            sum:=sum+a[i,r]*b[r,j];
            c[i,j]:=sum;
            write(c[i,j]:2,' ');
            end;
            writeln;
            end;
            end.

    • Perkalian Matriks
                program perkalian_matrix;
                uses crt;
                var
                a,b,c : array [1..50,1..50] of integer;
                i,j,k,x,y,z : integer;
                begin
                clrscr;
                writeln(‘Ukuran matrix A’);
                write(‘Baris : ‘);
                readln(x);
                write(‘Kolom : ‘);
                readln(y);
                writeln;
                writeln;
                writeln(‘Ukuran matrix B’);
                writeln(‘Baris : ‘,y);
                write(‘Kolom : ‘);
                readln(z);
                for i:=1 to x do
                for j:=1 to y do
                begin
                write(‘Elemen A[',i,',',j,'] : ‘);
                readln(a[i,j]);
                end;
                writeln;
                for i:=1 to y do
                for j:=1 to z do
                begin
                write(‘Elemen B[',i,',',j,'] : ‘);
                readln(b[i,j]);
                end;
                for i:=1 to x do
                for j:=1 to z do
                for k:=1 to y 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 x do
                begin
                for j:=1 to z do
                write(c[i,j],’ ‘);
                writeln;
                end;
                writeln;
                readln;
                end.

      0 komentar:

      Posting Komentar

       

      Reta Noorina Prastika 1311100090 Blak Magik is Designed by productive dreams for smashing magazine Bloggerized by Ipiet
      Thanks to Blogger Templates Blog | Distributed by Deluxe Templates © 2008