Oleh:
Dara
Nadinda (D1041141015)
Aldi
Reynaldi (D1041141019)
Naufal
Harits Pratama (D1041141037)
SOAL
Diketahui
unsur-unsur pada periode ketiga di dalam tabel periodik adalah
15P, 18Ar, 14Si, 13Al, 17Cl, 11Na, 12Mg, 16S
Buatlah
algoritma dan program menyusun unsur-unsur tersebut sesuai dengan urutan nomor
atomnya!
JAWAB:
A.
Algoritma
B. Program dengan Bahasa Pascal
n ← 8
U[1] ← 15
U[2] ← 18
U[3] ← 14
U[4] ← 13
U[5] ← 17
U[6] ← 11
U[7] ← 12
U[8] ← 16
for x ← 2 to n do
begin
key ← u[x]
y ← x
while ((y > 1) AND (u[y-1] > key)) do
begin
u[y] ← u[y-1];
y ← y-1
end
u[y] ← key
end
for y ← 1 to n do
begin
if u[y] = 11 then write('Na')
else if u[y] = 12 then write (' Mg')
else if u[y] = 13 then write (' Al')
else if u[y] = 14 then write (' Si')
else if u[y] = 15 then write (' P')
else if u[y] = 16 then write (' S')
else if u[y] = 17 then write (' Cl')
else if u[y] = 18 then write (' Ar')
else write('salah input angka')
end
end
B. Program dengan Bahasa Pascal
program periode3;
uses crt;
var u : array[1..8] of integer;
n, x, y, key : integer;
begin
n := 8;
u[1] := 15;
u[2] := 18;
u[3] := 14;
u[4] := 13;
u[5] := 17;
u[6] := 11;
u[7] := 12;
u[8] := 16;
for x := 2 to n do
begin
key := u[x];
y := x;
while ((y > 1) AND (u[y-1] > key)) do
begin
u[y] := u[y-1];
y := y-1;
end;
u[y] := key;
end;
for y := 1 to n do
begin
if u[y] = 11 then write('Na')
else if u[y] = 12 then write (' Mg')
else if u[y] = 13 then write (' Al')
else if u[y] = 14 then write (' Si')
else if u[y] = 15 then write (' P')
else if u[y] = 16 then write (' S')
else if u[y] = 17 then write (' Cl')
else if u[y] = 18 then write (' Ar')
else write('salah input angka');
end;
readkey;
end.
C. Output
No comments:
Post a Comment