Jumat, 02 Maret 2012
rumah matrik array matrik
program matrix;
uses crt;
type data = array[1..10,1..10] of longint;
var matrix1,matrix2 : data;
baris,kolom,pil : integer;
procedure isimatrik;
var i,j : longint;
begin
writeln('MENENTUKAN ORDO MATRIX 1');
write('Masukan banyak baris = ');readln(baris);
write('Masukan banyak kolom = ');readln(kolom);
for i:=1 to baris do
for j:=1 to kolom do
begin
gotoxy(j*10,i*5);
readln(matrix1[i,j]);
end;
clrscr;
writeln('MENENTUKAN ORDO MATRIX 2');
write('Masukan banyak baris = ');readln(baris);
write('Masukan banyak kolom = ');readln(kolom);
for i:=1 to baris do
for j:=1 to kolom do
begin
gotoxy(j*10,i*5);
readln(matrix2[i,j]);
end;
end;
procedure jumlahmatrik(m1,m2 : data);
var hasil : data;
i,j : integer;
begin
for i:=1 to baris do
for j:=1 to kolom do
begin
hasil[i,j]:=m1[i,j]+m2[i,j];
end;
clrscr;
writeln('Hasil penjumlahan dari MATRIX');
for i:=1 to baris do
for j:=1 to kolom do
begin
gotoxy(j*10,i*5);
write(hasil[i,j]);
end;
end;
procedure kurangmatrik(m1,m2 : data);
var hasil : data;
i,j : integer;
begin
for i:=1 to baris do
for j:=1 to kolom do
begin
hasil[i,j]:=m1[i,j]-m2[i,j];
end;
clrscr;
writeln('Hasil pengurangan dari MATRIX');
for i:=1 to baris do
for j:=1 to kolom do
begin
gotoxy(j*10,i*5);
write(hasil[i,j]);
end;
end;
procedure kalimatrik(m1,m2 : data);
var hasil : data;
i,j,z : integer;
begin
for i:=1 to baris do
for j:=1 to kolom do
begin
hasil[i,j]:=0;
for z:=1 to baris do
hasil[i,j]:=hasil[i,j]+matrix1[i,z]*matrix2[z,j];
end;
clrscr;
writeln('Hasil Perkalian dari MATRIX');
for i:=1 to baris do
for j:=1 to kolom do
begin
gotoxy(j*10,i*5);
write(hasil[i,j]);
end;
end;
begin clrscr;
writeln('================================');
writeln(' M E N U RUMUR MATEMATIKA');
writeln('================================');
writeln(' 1. Penjumlahan Matrix');
writeln(' 2. Pengurangan Matrix');
writeln(' 3. Perkalian Matrix');
writeln('================================');
write('Pilihan = ');readln(pil);
clrscr;
case pil of
1 : begin
isimatrik;
jumlahmatrik(matrix1,matrix2);
end;
2 : begin
isimatrik;
kurangmatrik(matrix1,matrix2);
end;
3 : begin
isimatrik;
kalimatrik(matrix1,matrix2);
end;
end;
readln;
end.
Langganan:
Posting Komentar (Atom)
Tidak ada komentar:
Posting Komentar