Selasa, 26 Juni 2012

Program invers (3 dimensi)

uses wincrt;
label  hitung;

var
    mat,adj : array [1..5,1..5] of integer;
    det,i,j : integer;
    c:char;

begin

  clrscr;
         { tampilan awal keterangan matrik }
  gotoxy(20,4);
  writeln('Matriks Ordo 2 x 2');

  gotoxy(15,5);
  writeln('-------------------------');

  gotoxy(15,7);
  writeln('1. Input data matrik ');

  gotoxy(15,8);
  writeln('2. Menentukan Adjoin Matrik');

  gotoxy(15,9);
  writeln('3. Mencari determinan matriks');

  gotoxy(15,10);
  writeln('4. Mencari Invers matriks');
  readln;

   if c = #13 then goto hitung;

           {end tampilan awal keterangan matrik}

           {mulai proses input}
hitung:
      begin
        clrscr;
        writeln('Input Matrik Ordo 2x2');
        writeln('-------------------------');
        for i := 1 to 2 do begin
           for j:= 1 to 2 do begin
               write('matrik ke ',i,' ',j,': ');readln(mat[i,j]);
           end;
           writeln;
        end;

        for i := 1 to 2 do begin
         write('|');
          for j := 1 to 2 do begin
            write(' ',mat[i,j],' ');
              if j = 2 then write ('|');
          end;
          writeln;
        end;
                 {end proses input matrik}

        writeln;
        writeln;
                 {mulai adjoin matrik dan determinan}

        writeln('Adjoin matrik Ordo 2x2');
        writeln('-----------------------');

        adj[1,1] := mat[2,2];
        adj[1,2] := mat[1,2] * -1;
        adj[2,1] := mat[2,1] * -1;
        adj[2,2] := mat[1,1];

          for i := 1 to 2 do begin
           write('|');
             for j := 1 to 2 do begin
                 write(' ',adj[i,j],' ');
                   if j = 2 then write('|');
             end;
             writeln;
          end;
        writeln;

        det := (mat[1,1] * mat [2,2]) - (mat[1,2] * mat[2,1]);

        write('Determinan dari matrik diatas adalah ');
        writeln(det);
        writeln;
                  {end of adjoin and determinan}

                  {mulai menghitung invers matrik}

        writeln('Invers Matrik ');
        writeln('----------------');
        writeln;

        for i := 1 to 2 do begin
         write('|');
          for j := 1 to 2 do begin
            write(' ',adj[i,j]/det:3:2,' ');
              if j = 2 then write('|');
          end;
          writeln;writeln;writeln;
       end;
                    {end of hitung invers matrik}

       end;
readln;
end.

Tidak ada komentar:

Posting Komentar