program Menjumlahkan_Elemen_Matriks;
uses crt;
type
matriks= array [1..5,1..5] of integer;
var
A: matriks;
M, N, Jumlah : integer; {M: banyaknya baris, N: banyaknya kolom}
Procedure isi_matriks(var M,N: integer; var A:matriks);
var
i,j: integer;
begin
write('Banyaknya Baris : ');readln(M);
write('Banyaknya Kolom : ');readln(N);
clrscr;
{Mengisi matriks A}
gotoxy(12,1);write('Matriks A');
gotoxy(12,2);write('=========');
for i:= 1 to M do
begin
for j:= 1 to N do
begin
gotoxy(j*5,i+2);readln(A[i,j]);
end;
end;
end;
Procedure jumlah_elemen(M,N: integer; var A:matriks; var Jumlah: integer);
var
i,j: integer;
begin
Jumlah:=0;
for i:=1 to M do
for j:= 1 to N do
begin
gotoxy(j*5,i+2);Jumlah:= Jumlah + A[i,j];
end;
end;
Procedure tampil_jumlah_elemen(M,N: integer; var A:matriks; var Jumlah: integer);
var
i,j:integer;
begin
{menampilkan matriks hasil penjumlahan}
gotoxy(12,1);write('Matriks A');
gotoxy(12,2);write('=========');
for i:=1 to M do
for j:= 1 to N do
begin
gotoxy(j*5,i+2);writeln(A[i,j]);
end;
gotoxy(2,8);write('Total elemen matriks adalah ',Jumlah);
end;
begin
isi_matriks(M,N,A);
jumlah_elemen(M,N,A,Jumlah);
tampil_jumlah_elemen(M,N,A,Jumlah);
readln;
end.
uses crt;
type
matriks= array [1..5,1..5] of integer;
var
A: matriks;
M, N, Jumlah : integer; {M: banyaknya baris, N: banyaknya kolom}
Procedure isi_matriks(var M,N: integer; var A:matriks);
var
i,j: integer;
begin
write('Banyaknya Baris : ');readln(M);
write('Banyaknya Kolom : ');readln(N);
clrscr;
{Mengisi matriks A}
gotoxy(12,1);write('Matriks A');
gotoxy(12,2);write('=========');
for i:= 1 to M do
begin
for j:= 1 to N do
begin
gotoxy(j*5,i+2);readln(A[i,j]);
end;
end;
end;
Procedure jumlah_elemen(M,N: integer; var A:matriks; var Jumlah: integer);
var
i,j: integer;
begin
Jumlah:=0;
for i:=1 to M do
for j:= 1 to N do
begin
gotoxy(j*5,i+2);Jumlah:= Jumlah + A[i,j];
end;
end;
Procedure tampil_jumlah_elemen(M,N: integer; var A:matriks; var Jumlah: integer);
var
i,j:integer;
begin
{menampilkan matriks hasil penjumlahan}
gotoxy(12,1);write('Matriks A');
gotoxy(12,2);write('=========');
for i:=1 to M do
for j:= 1 to N do
begin
gotoxy(j*5,i+2);writeln(A[i,j]);
end;
gotoxy(2,8);write('Total elemen matriks adalah ',Jumlah);
end;
begin
isi_matriks(M,N,A);
jumlah_elemen(M,N,A,Jumlah);
tampil_jumlah_elemen(M,N,A,Jumlah);
readln;
end.
Post a Comment