program Menjumlahkan_Elemen_Baris_Kolom;
uses crt;
type
matriks= array [1..5,1..5] of integer;
var
A: matriks;
M, N : integer; {M: banyaknya baris, N: banyaknya kolom}
Procedure isi_matriks(var M,N: integer; var A:matriks);
var
i,j: integer;
begin
clrscr;
gotoxy(7,7);write('Banyaknya Baris : ');readln(M);
gotoxy(7,8);write('Banyaknya Kolom : ');readln(N);
{Mengisi matriks}
clrscr;
gotoxy(12,1);write('Isikan 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_Baris_Kolom(var M,N: integer; var A:matriks);
var
i,j: integer;
begin
{Penjumlahan Baris}
for i:= 1 to M do
begin
A[i, N+1]:=0;
for j:= 1 to N do
begin
A[i, N+1]:= A[i,N+1] + A[i,j];
end;
end;
{Penjumlahan Kolom}
for j:= 1 to N do
begin
A[M+1,j]:=0;
for i:= 1 to M do
begin
A[M+1,j]:= A[M+1,j] + A[i,j];
end;
end;
end;
Procedure Tampil_Jumlah_Baris_Kolom(var M,N: integer; var A:matriks);
var
i,j: integer;
begin
{Tampil Jumlah Elemen Baris dan Kolom Matriks}
gotoxy(5,1);write('Jumlah Elemen Baris dan Kolom');
gotoxy(5,2);write('=============================');
for i:= 1 to M do
begin
for j:= 1 to N do
begin
gotoxy(j*5,i+2);writeln(A[i,j]);
end;
end;
{Tampil Baris}
for i:= 1 to M do
begin
for j:= 1 to N do
gotoxy((N+1)*5,i+2);write('| ',A[i,N+1]);
end;
{Tampil Kolom}
for j:= 1 to N do
begin
for i:= 1 to M do
begin
gotoxy(j*5,M+3);write('-');
gotoxy(j*5,M+4);write(A[M+1,j]);
end;
end;
end;
begin
isi_matriks(M,N,A);
Jumlah_Baris_Kolom(M,N,A);
Tampil_Jumlah_Baris_Kolom(M,N,A);
readln;
end.
uses crt;
type
matriks= array [1..5,1..5] of integer;
var
A: matriks;
M, N : integer; {M: banyaknya baris, N: banyaknya kolom}
Procedure isi_matriks(var M,N: integer; var A:matriks);
var
i,j: integer;
begin
clrscr;
gotoxy(7,7);write('Banyaknya Baris : ');readln(M);
gotoxy(7,8);write('Banyaknya Kolom : ');readln(N);
{Mengisi matriks}
clrscr;
gotoxy(12,1);write('Isikan 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_Baris_Kolom(var M,N: integer; var A:matriks);
var
i,j: integer;
begin
{Penjumlahan Baris}
for i:= 1 to M do
begin
A[i, N+1]:=0;
for j:= 1 to N do
begin
A[i, N+1]:= A[i,N+1] + A[i,j];
end;
end;
{Penjumlahan Kolom}
for j:= 1 to N do
begin
A[M+1,j]:=0;
for i:= 1 to M do
begin
A[M+1,j]:= A[M+1,j] + A[i,j];
end;
end;
end;
Procedure Tampil_Jumlah_Baris_Kolom(var M,N: integer; var A:matriks);
var
i,j: integer;
begin
{Tampil Jumlah Elemen Baris dan Kolom Matriks}
gotoxy(5,1);write('Jumlah Elemen Baris dan Kolom');
gotoxy(5,2);write('=============================');
for i:= 1 to M do
begin
for j:= 1 to N do
begin
gotoxy(j*5,i+2);writeln(A[i,j]);
end;
end;
{Tampil Baris}
for i:= 1 to M do
begin
for j:= 1 to N do
gotoxy((N+1)*5,i+2);write('| ',A[i,N+1]);
end;
{Tampil Kolom}
for j:= 1 to N do
begin
for i:= 1 to M do
begin
gotoxy(j*5,M+3);write('-');
gotoxy(j*5,M+4);write(A[M+1,j]);
end;
end;
end;
begin
isi_matriks(M,N,A);
Jumlah_Baris_Kolom(M,N,A);
Tampil_Jumlah_Baris_Kolom(M,N,A);
readln;
end.
4 comments
makasih yah, sangat membantu....
mas mau tanya
kalo misal baris /kolom nya lebih dari 5?
itu gmana gotoxy nya?
makasih infonya sangat membantu
Post a Comment