Penjumlahan Matrik dan array Dengan Bahasa Pascal
Penjumlahan Matrik :
Input:
program penjumlahan_matrik;uses WinCrt;var matriks1, matriks2, matrik_hasil : array[1..3,1..3]of integer; i,j:integer;beginRandomize;for i:=1 to 3 dofor j:=1 to 3 do begin matriks1[i,j]:=Random(10); matriks2[i,j]:=Random(10); end;
writeln('matriks 1');for i:=1 to 3 do begin for j:=1 to 3 do begin write(matriks1[i,j]:5); end; writeln; end;
writeln('matriks 2');for i:=1 to 3 do begin for j:=1 to 3 do begin write(matriks2[i,j]:5); end; writeln; end;
for i:=1 to 3 do for j:=1 to 3 do begin matrik_hasil[i,j]:=matriks1[i,j]+matriks2[i,j]; end;
writeln('Hasil penjumlahan matriks'); for i:=1 to 3 do begin for j:=1 to 3 do begin write(matrik_hasil[i,j]:5); end; writeln; end;
end.
Array :
input :
program data_diri;
uses Wincrt;
var
Nim : array[1..20]of string[10];
Nama: array[1..20]of string[25];
Nilai: array[1..20]of integer;
Umur:array[1..20] of Byte;
banyak, i : integer;
Begin
Write('jumlah data yang akan dimasukkan:');readln(banyak);
for i :=1 to banyak do
begin
Write('Nim = ');Readln(Nim[i]);
Write('Nama = ');Readln(Nama[i]);
Write('Nilai = ');Readln(Nilai[i]);
Write('umur = ');Readln(Umur[i]);
end;
writeln;
writeln('NIM || Nama || Nilai || Umur');
writeln('-------------------------------------------------------------');
for i:=1 to banyak do
writeln(Nim[i],Nama[i]:25,Nilai[i]:22, '',Umur[i]:8);
end.
Tidak ada komentar: