Penjumlahan 2Matrix dengan Procedure

program perkalian_dua_matrik2x2;

{$APPTYPE CONSOLE}

uses
SysUtils;

type matrix = array [1..2,1..2] of real;

procedure BacaMatrix(var M : matrix);
var i,j : integer;
begin
for i := 1 to 2 do
for j := 1 to 2 do
begin
write(‘masukkan nilai matrix (‘,i,’,’,j,’) : ‘);
readln(M[i,j]);
end;
end;

procedure TulisMatrix(M : matrix);
var i,j : integer;
begin
writeln(‘Hasil Penjumlahan Matrix: ‘);
for i := 1 to 2 do
begin
for j := 1 to 2 do
write(M[i,j]:8:0);
writeln;
end;
end;

procedure TambahMatrix(M1,M2 : matrix;
var M3 : matrix);
var i,j : integer;
begin
for i := 1 to 2 do
for j := 1 to 2 do
M3[i,j] := M1[i,j] + M2[i,j];
end;

var A,B,C : matrix;
begin
writeln;
writeln(‘<<<===================================>>>’);
writeln(‘PROGRAM PENJUMLAHAN DUA BUAH MATRIX 2 X 2’);
writeln;
writeln(‘Silahkan masukkan nilai matrix’);
writeln;
writeln(‘MATRIX PERTAMA:’);
BacaMatrix(A);
writeln;
writeln(‘MATRIX KEDUA:’);
BacaMatrix(B);
writeln;
writeln(‘Tekan ENTER untuk melihat hasilnya’);
readln;
TambahMatrix(A,B,C);
TulisMatrix(C);
writeln;
writeln(‘Sekarang…Coba TEKAN ENTER lagi” Untuk keluar program^^’);
readln;
end.

Hasil Setelah di RUN(F9 pd Delphi):
<<<===================================>>>
PROGRAM PENJUMLAHAN DUA BUAH MATRIX 2 X 2

Silahkan masukkan nilai matrix

MATRIX PERTAMA:
masukkan nilai matrix (1,1) : 12
masukkan nilai matrix (1,2) : 32
masukkan nilai matrix (2,1) : 4
masukkan nilai matrix (2,2) : 9

MATRIX KEDUA:
masukkan nilai matrix (1,1) : 34
masukkan nilai matrix (1,2) : 5
masukkan nilai matrix (2,1) : 12
masukkan nilai matrix (2,2) : 65

Tekan ENTER untuk melihat hasilnya

Hasil Penjumlahan Matrix:
46 37
16 74

Sekarang…Coba TEKAN ENTER lagi’ Untuk keluar program^^

~ oleh delz21 pada November 28, 2009.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

 
%d blogger menyukai ini: