Sabtu, 23 Januari 2016

CONTOH PROGRAM PASCAL: Matriks

CODING:

Program matrik;
Uses crt;
Type data = array [1..2,1..2] of longint;
Var
            m,adj : data;
i,j,pil,det : longint;

procedure input;
begin
clrscr;
writeln('A = ');
for i := 1  to 2 do
                        begin
                                    for j:= 1 to 2 do
                                                begin
                                                            gotoxy(j*5,i);
                                                            read(m[i,j]);
                                                end;
                        end;
end;

procedure output;
begin
            clrscr;
            writeln ('A = ');
            for i:= 1 to 2 do
                        begin
                                    for j:= 1 to 2 do
                                                begin
                                                            gotoxy(j*5,i);
                                                            write(m[i,j]);
                                                end;
                        end;
            readln;
end;

procedure determinan;
begin
            clrscr;
            det:= (m[1,1] * m[2,2]) - (m[1,2] * m[2,1]);
            writeln('Determinan = ',det);
            readln;
end;

procedure transpose;
begin
            clrscr;
            writeln('Transpose =  ');
            for i:= 1 to 2 do
                        begin
                                    for j:= 1 to 2 do
                                                begin
                                                            gotoxy(j*5,i+1);
                                                            write(m[j,i],' ');
                                                end;
                        end;
            readln;
end;

procedure inverse;
begin
            clrscr;
            writeln('Adjoin = ');
            for i:= 1 to 2 do
                        begin
                                    for j:= 1 to 2 do
                                                begin
                                                            adj[1,1]:=   1 * m[2,2];
                                                            adj[1,2]:=  -1 * m[1,2];
                                                            adj[2,1]:=  -1 * m[2,1];
                                                            adj[2,2]:=   1 *m[1,1];
                                                            write (adj[i,j] : 3, ' ');
                                                end;
                                    writeln;
                        end;
writeln;

det:= (m[1,1] * m[2,2]) - (m[1,2] * m[2,1]);
writeln('Determinan = ',det);
writeln;

writeln('Invers =  ');
for i:= 1 to 2 do
            begin
                        for j:= 1 to 2 do
                                    begin
                                                write(adj[i,j]/det:7:2,' ');
                                    end;
                        writeln;
            end;
readln;
end;

begin
            repeat;
                        clrscr;
                        writeln('MATRIK');
                        writeln('1. Input');
                        writeln('2. Output');
                        writeln('3. Determinan');
writeln('4. Transpose');
writeln('5. Inverse');
writeln('6. Exit');
writeln('----------------------');
writeln('pilih [1..6] : ');
readln(pil);
case pil of
            1: input;
            2: output;
            3: determinan;
            4: transpose;
            5: inverse;
End;
            Until (pil) = 6;
end.

OUTPUT


Tampilan Menu Matriks
Input Nilai Matriks
Nilai Determinan dari matriks yang tadi di input. 
Program akan menghitung nilai yg tadi dimasukan dengan rumus determinan (ad-cb) atau seperti pada kodingannya det:= (m[1,1] * m[2,2]) - (m[1,2] * m[2,1]);. Jadi, 1,1 = 600, 2,2= 35, 1,2=5, dan 2,1=250. Dan hasilnya 208750.
Nilai Inverse




Tidak ada komentar:

Posting Komentar