PROGRAM PASCAL MANGHITUNG DETERMINAN MATRIKS ORDO 2X2


Hello sahabat , bagi yang mau menghitung determinan, invers, perkalian matriks, nih admin kasih bahasa programnya , silahkan dicopy ..

 

uses crt;

label ulang;

type matrik = array[1..3,1..3] of real;

var a,b,c,g,h,k : matrik;

    p,i,j,l : integer;

    d,e,y,z : real;

    ch : char;

begin

     repeat;

     clrscr;

           ulang :

           writeln;

           writeln('Entri matrik A');

           for i := 1 to 2 do

           begin

                for j := 1 to 2 do

                   begin

                   write('A[',i,',',j,'] = ');readln(a[i,j]);

                   end;

           end;

           writeln('Entri matrik B');

           for i := 1 to 2 do

           begin

                for j := 1 to 2 do

                begin

                     write('B[',i,',',j,'] = ');readln(b[i,j]);

                end;

           end;

           clrscr;

           writeln('=============== MATRIK ORDO 2X2 ===============');

           writeln;

           writeln('--Matrik A--');

           writeln;

           for i := 1 to 2 do

               begin

                    for j := 1 to 2 do write (a[i,j]:4:0);

                    writeln;

               end;

           writeln;

           writeln('--Matrik B--');

           writeln;

           for i := 1 to 2 do

               begin

                    for j := 1 to 2 do write(b[i,j]:4:0);

                    writeln;

               end;

           writeln;

           writeln('Matrik Identitas');

           writeln;

           for i := 1 to 2 do

               begin

                    for j := 1 to 2 do

                        begin

                             if (i=j) then write('1':4) else if (i<>j) then write('0':4);

                             if (j>=2) then writeln;

                        end;

               end;

           writeln;

           write('<<press ENTER>>');

           readln;

           clrscr;

           writeln('                       Silahkan pilih menu di bawah ini : ');

           writeln;

           writeln('               1. Determinan Matrik');

           writeln('               2. Invers matrik');

           writeln('               3. Perkalian matrik');

           writeln('               4. Perkalian matrik dengan identitas');

           writeln;

           write('                 pilihan = '); readln(p);

           clrscr;

           if (p=1) then

           begin

                 writeln('--Matrik A--');

                 writeln;

                 for i := 1 to 2 do

                     begin

                          for j := 1 to 2 do write (a[i,j]:4:0);

                          writeln;

                     end;

                 writeln;

                 writeln('--Matrik B--');

                 writeln;

                 for i := 1 to 2 do

                     begin

                          for j := 1 to 2 do write(b[i,j]:4:0);

                          writeln;

                     end;

                     writeln;

                  d:=((a[1,1])*(a[2,2])) - ((a[1,2])*(a[2,1]));

                  e:=(b[1,1])*(b[2,2]) - (b[1,2])*(b[2,1]) ;

                  writeln('Determinan Matrik A adalah = ',d:4:2);

                  writeln('Determinan Matrik B adalah = ',e:4:2);

                  if (d=0) and (e=0) then goto ulang;

           end

           else

           if (p=2) then

           begin

                clrscr;

                writeln('--Matrik A--');

                writeln;

                for i := 1 to 2 do

                    begin

                         for j := 1 to 2 do write (a[i,j]:4:0);

                         writeln;

                    end;

                writeln;

                writeln('--Matrik B--');

                writeln;

                for i := 1 to 2 do

                    begin

                         for j := 1 to 2 do write(b[i,j]:4:0);

                         writeln;

                    end;

                writeln;

                d:=((a[1,1])*(a[2,2])) - ((a[1,2])*(a[2,1]));

                e:=(b[1,1])*(b[2,2]) - (b[1,2])*(b[2,1]) ;

                writeln('Determinan Matrik A adalah = ',d:4:2);

                writeln('Determinan Matrik B adalah = ',e:4:2);

                if (d=0) and (e=0) then goto ulang;

                writeln;

                writeln('Invers Matrik A adalah : ');

                writeln;

                z := a[1,1];

                a[1,1] := a[2,2]/d;

                a[2,2] := z/d;

                a[1,2] := a[1,2]/-d;

                a[2,1] := a[2,1]/-d;

                for i := 1 to 2 do

                    begin

                         for j := 1 to 2 do write (a[i,j]:7:2);

                         writeln;

                    end;

                writeln;

                writeln('Invers Matrik B adalah : ');

                writeln;

                y := b[1,1];

                b[1,1] := b[2,2]/e;

                b[2,2] := y/e;

                b[1,2] := b[1,2]/-e;

                b[2,1] := b[2,1]/-e;

                for i := 1 to 2 do

                    begin

                         for j := 1 to 2 do write (b[i,j]:7:2);

                         writeln;

                    end;

           end

           else

    if (p=3) then

    begin

         clrscr;

         writeln('--Matrik A--');

         writeln;

         for i := 1 to 2 do

         begin

              for j := 1 to 2 do write (a[i,j]:4:0);

              writeln;

         end;

         writeln;

         writeln('--Matrik B--');

         writeln;

         for i := 1 to 2 do

             begin

                  for j := 1 to 2 do write(b[i,j]:4:0);

                  writeln;

             end;

         writeln;

         writeln('Hasil perkalian adalah ');

         for i := 1 to 2 do

             for j := 1 to 2 do

                 begin

                      g[i,j] := 0;

                      for l := 1 to 2 do

                      g[i,j] := g[i,j]+a[i,l]*b[l,j];

                      write(g[i,j]:7:2);

                      if (j=2) then writeln;

                  end;

    end

    else

    if (p=4) then

    begin

         clrscr;

         writeln('--Matrik A--');

         writeln;

         for i := 1 to 2 do

            begin

                 for j := 1 to 2 do write (a[i,j]:4:0);

                 writeln;

            end;

         writeln;

         writeln('--Matrik B--');

         writeln;

         for i := 1 to 2 do

            begin

                 for j := 1 to 2 do write(b[i,j]:4:0);

                 writeln;

            end;

         writeln;

         writeln('Matrik Identitas');

         writeln;

         for i := 1 to 2 do

            begin

                 for j := 1 to 2 do

                     begin

                          if (i=j) then write('1':4) else if (i<>j) then write('0':4);

                          if (j>=2) then writeln;

                     end;

                 end;

        writeln;

        writeln('Hasil perkalian Matrik A dengan Matrik Identitas adalah ');

        for i := 1 to 2 do

            for j := 1 to 2 do

                begin

                     g[i,j] := 0;

                     for l := 1 to 2 do

                     h[i,j] := a[i,j]*1;

                     write(h[i,j]:7:2);

                     if (j=2) then writeln;

                end;

        writeln;

        writeln('Hasil perkalian Matrik B dengan Matrik Identitas adalah ');

        for i := 1 to 2 do

            for j := 1 to 2 do

                begin

                     k[i,j] := 0;

                     for l := 1 to 2 do

                     k[i,j] :=b[i,j]*1;

                     write(k[i,j]:7:2);

                     if (j=2) then writeln;

                end;

    end;

    writeln;

    write('Mau ulang lagi? [Y/N] ');

    repeat ch := readkey; until Upcase (ch) in ['Y','N'];

    until Upcase(ch) = 'N';

 end.

 

Output :


  


Comments