hasil := 1;
for i:= 3 to 10 do
begin
if (i mod 2 > 0) then
begin
hasil := hasil*i;
hasil := hasil*(-1);
end;
else
hasil := hasil div 2;
hasil := hasil * (-1);
end;
writeln(hasil);
keluaran dari algoritma tersebut adalah…
Perhatikan potongan algoritma berikut.
Jawaban:
Hasil = 1
i = 3 sampai 10
3 = 1 * 3 = 3 = -3
4 = -3 div 2 = -1 = 1
5 = 1 * 5 = 5 = -5
6 = -5 div 2 = -2 = 2
7 = 2 * 7 = 14 = -14
8 = -14 div 2 = -7 = 7
9 = 7 * 9 = 63 = -63
10 = -63 div 2 = -31 = 31
TOLONG DI CEK LAGI TAKUT SALAH