Program Penjumlahan Matrik (PASCAL)

Berikut ini adalah program menampilkan dan menjumlahkan dua matrik :
Selamat mencoba

program Penjumlahan_Matrix;

uses crt;
const kolom=10;
baris=10;
type matrix=array[1..baris,1..kolom] of integer;
var matrix_A,matrix_B:matrix;
a,b:integer;
procedure InputMatrix(var x:matrix);
var i,j:integer;
begin
for i := 1 to a do
begin
for j := 1 to b do
begin
write('Masukkan Elemen[',i,',',j,']:');readln(x[i,j]);
end;
end;
end;
procedure CetakMatrix(var x:matrix);
var i,j:integer;
begin
for i := 1 to a do
begin
for j := 1 to b do
begin
write(x[i,j]:4);
end;
writeln;
end;
end;
procedure JumlahMatrix(var x,y:matrix);
var z:matrix;
i,j:integer;
begin
for i:=1 to a do
begin
for j:=1 to b do
begin
z[i,j]:=x[i,j] + y[i,j];
write(z[i,j]:4);
end;
writeln;
end;
end;
begin
clrscr;
write('Masukkan Jumlah Baris : ');readln(a);
write('Masukkan Jumlah kolom : ');readln(b);
if (a>10) or (b>10) then
begin
writeln('Max Kolom dan baris adalah 10!');
exit;
end;
clrscr;
writeln('Input Matrix A');
InputMatrix(matrix_A);
writeln;
writeln('Input Matrix B');
InputMatrix(matrix_B);
clrscr;
writeln('Matrix A');
CetakMatrix(matrix_A);
writeln;
writeln('Matrix B');
CetakMatrix(matrix_B);
writeln;
writeln('Penjumlahan Matrix A dan Matrix B');
JumlahMatrix(matrix_A,matrix_B);
readkey;
end.

Pascal Konversi Bilangan Desimal ke Biner (PASCAL)

-->Perhitungan secara manual :

Step 1. 17 dibagi 2 mendapatkan 8 sisa 1
Step 2. 8 dibagi 2 mendapatkan 4 sisa 0
Step 3. 4 dibagi 2 mendapatkan 2 sisa 0
Step 4. 2 dibagi 2 mendapatkan 1 sisa 0


Berikut adalah program konversi bilangan desimal ke biner dengan menggunakan program Pascal,

Program konversi_Desimal_to_Biner;
uses crt;
var bilangan:integer;

function decToBin(desimal:integer):string;
var hasilbagi, sisa:integer;
bin:char;
bilBiner:string;
begin
hasilBagi := desimal div 2;
bilBiner := '';

while (hasilBagi >= 1) do
begin
sisa := desimal mod 2;
if (sisa = 0)then bin := '0'
else if (sisa = 1) then bin := '1';

bilBiner:=bin + bilBiner;

desimal := hasilBagi;
hasilBagi := desimal div 2;
end;
decToBin:='1' + bilBiner;
end;

begin
clrscr;
writeln('KONVERSI BILANGAN DESIMAL KE BINER');
writeln;
write('masukkan bilangan : ');readln(bilangan);
write('Bilangan Binernya : ', decToBin(bilangan));
readkey;
end.



Sekarang kebalikannya dari bilangan biner ke bilangan desimal
-->
(10110)2 = 1×24 + 0×23 + 1×22 + 1×21 + 0×20
(10110)2 = 16 + 0 + 4 + 2 + 0 = 22
Bila di aplikasikan dalam program Pascal :



Program konversi_Biner_to_Dec;
uses crt;
var bilBiner : String;

function pangkat(a, b : integer): integer;
var i, hasil : integer;
begin
hasil := 1;
for i:=1 to b do
begin
hasil := hasil * a;
end;
pangkat := hasil;
end;

function bin2Dec(biner : string) : integer;
var n, sum, i : integer;
begin
n := length(biner);
sum := 0;
for i := n-1 downto 0 do
begin
if (biner [n-1] = '0') then sum := sum + 0 * pangkat (2, i)
else if (biner [n-1] = '1') then sum := sum + 1 * pangkat (2, i);
end;
bin2Dec := sum;
end;

begin
clrscr;
writeln('KONVERSI BILANGAN BINER KE DESIMAL');
writeln;
write('Masukkan bilangan Biner : ');readln(bilBiner);
write ('Bilangan Desimalnya : ', bin2Dec(bilBiner));
readkey;
end.
 

Usage Rights

DesignBlog BloggerTheme comes under a Creative Commons License.This template is free of charge to create a personal blog.You can make changes to the templates to suit your needs.But You must keep the footer links Intact.