Kamis, 15 November 2012

LP ALIN II


Soal :
1. Buatlah Aljabar pemrograman perkalian pada matriks ?

2. Buatlah Aljabar pemrograman transpose pada matriks ?
3. Buatlah Aljabar pemrograman determinan pada matriks ?

Jawaban :


uses crt;
type t = object
m1, m2 : array [1..2,1..2] of integer;
lok : array [1..4] of integer;
procedure input;
procedure tampil;
procedure kali;
procedure transpose;
procedure determinan;
end;
var m: t;
i,j,k,det,det2,pil : integer;


procedure t.input;
begin
     clrscr;
     writeln ('input matrix I');
     for i:= 1 to 2 do
     begin
          for j:= 1 to 2 do
          begin
               write('elemen matrix [',i,',',j,']: ');
               readln (m1[i,j]);
          end;
     end;
     gotoxy (35,1); writeln('inputan matrix II');
     k:=2;
     for i:=1 to 2 do
     begin
          for j:=1 to 2 do
          begin
               gotoxy (35,k);
               inc (k);
               write('elemen matrix [',i,',',j,']: ');
               readln(m2[i,j]);
          end;
     end;
end;

procedure t.tampil;
begin
     writeln;
     writeln ('matrix I ');
     writeln (m1[1,1]:5,m1[1,2]:5);
     writeln (m1[2,1]:5,m1[2,2]:5);
     gotoxy (35,7); writeln ('matrix II');
     gotoxy (35,8); writeln (m2[1,1]:5,m2[1,2]:5);
     gotoxy (35,9); writeln (m2[2,1]:5,m2[2,2]:5);
     readln;
end;

procedure t.kali;
begin
     gotoxy (23,11);writeln('hasil perkalian matrix');
     lok[1] := ((m1[1,1] * m2[1,1])+(m1[1,2] * m2[2,1]));
     lok[2] := ((m1[1,1] * m2[1,2])+(m1[1,2] * m2[2,2]));
     lok[3] := ((m1[2,1] * m2[1,1])+(m1[2,1] * m2[2,1]));
     lok[4] := ((m1[2,1] * m2[1,2])+(m1[2,1] * m2[2,2]));
     gotoxy(30,12); writeln(lok[1]:5,lok[2]:5);
     gotoxy(30,13); writeln(lok[3]:5,lok[4]:5);
     readln;
end;

procedure t.transpose;
begin
     clrscr;
     writeln;
     writeln ('matrix I ');
     writeln (m1[1,1]:5,m1[1,2]:5);
     writeln (m1[2,1]:5,m1[2,2]:5);
     gotoxy (35,2); writeln ('matrix II');
     gotoxy (35,3); writeln (m2[1,1]:5,m2[1,2]:5);
     gotoxy (35,4); writeln (m2[2,1]:5,m2[2,2]:5);

     writeln;
     writeln ('Transpose matrix I');
     for i:= 1 to 2 do
     begin
          for j:= 1 to 2 do
          begin
               write(m1[j,i]:5);
          end;
      writeln;
     end;
     gotoxy (35,6); writeln('Transpose matrix II');
     k:=7;
     for i:=1 to 2 do
     begin
     gotoxy (35,k);
          for j:=1 to 2 do
          begin
               write(m2[j,i]:5);
          end;
     inc (k);
     end;
readln;
end;

procedure t.determinan;
begin
     clrscr;
     writeln;
     writeln ('matrix I ');
     writeln (m1[1,1]:5,m1[1,2]:5);
     writeln (m1[2,1]:5,m1[2,2]:5);
     gotoxy (35,2); writeln ('matrix II');
     gotoxy (35,3); writeln (m2[1,1]:5,m1[1,2]:5);
     gotoxy (35,4); writeln (m2[2,1]:5,m2[2,2]:5);

det := (m1[1,1]*m1[2,2])-(m1[2,1]*m1[1,2]);
det2 := (m2[1,1]*m2[2,2])-(m2[2,1]*m2[1,2]);

writeln;
writeln ('Determinan Matrix I = ',det);
gotoxy (35,6); writeln ('Determinan Matrix II = ',det2);
readln;
end;

begin
     repeat
     clrscr;
     gotoxy (25,1); writeln ('<<<<< menu matrix >>>>>');
     gotoxy (25,2); writeln ('1. input matrix 1');
     gotoxy (25,3); writeln ('2. perkalian matrix');
     gotoxy (25,4); writeln ('3. transpose matrix');
     gotoxy (25,5); writeln ('4. determinan matrix');
     gotoxy (25,6); writeln ('5. keluar');
     gotoxy (25,7); writeln (' ===============================');
     gotoxy (25,8); write ('pilihan [1..5] : '); readln(pil);

case pil of

1: begin
        m.input;
        m.tampil;
   end;
2: m.kali;
3: m.transpose;
4: m.determinan;

end;
until pil=5;
end.


Output : 


0 komentar:

Posting Komentar

 
;