Program perulangan;
Deklarasi
:
i :
integer;
Algoritma
:
i ←
2
while i < 5 do
output (i, ' KALI PERULANGAN')
i ← i + 1;
endwhile
end.
Analisis :
T(n) = cop.c(n)
← :
4n
< :
4n
+ :
3n
ouput : 3n
T(n) = (4n)a + (4n)b + (3n)c + (3n)d
T(2) = 8a + 8b + 6c + 6d
Program ganjil_genap;
Deklarasi
:
a :
integer;
Algoritma
:
output (' MASUKKAN BILANGAN : ')
if (a mod 2 = 0) then
output ('genap')
else
output ('ganjil')
endif
end.
Analisis :
T(n) = cop.c(n)
mod :
1
= :
1
T(n) = 1a + 1b
T(1) = 1a + 1b
Program perkalian;
Deklarasi
:
n : integer;
x : integer;
angka : integer;
hasil : integer;
Algoritma
:
n ←
1;
angka ← 10
while n <= 9
do
x
← n + 1;
hasil ← x * angka;
output (x, ' * ', angka, ' = ', hasil);
n ← n +
1;
endwhile
end.
Analisis :
T(n) = cop.c(n)
← :
3n + 1
<= :
n + 9
+ :
2n
* :
1
T(n) = (3n + 1)a + (n + 9)b + (2n)c + 1d
T(1) = 4a + 10b + 2c + 1d
Program volume_balok;
Deklarasi :
panjang : real;
Deklarasi :
panjang : real;
lebar : real;
tinggi : real;
volume : real;
volume : real;
Algoritma
:
output ('Program Volume Balok')
output ('Masukkan Data')
output ('Panjang cm = ')
input (panjang)
output ('Lebar cm = ')
input (lebar)
output ('Tinggi cm = ')
input (tinggi)
volume ← panjang * lebar * tinggi;
output ('Hasil Volume = ', volume : 4 : 2, ' cm ^ 3 ');
end.
output ('Program Volume Balok')
output ('Masukkan Data')
output ('Panjang cm = ')
input (panjang)
output ('Lebar cm = ')
input (lebar)
output ('Tinggi cm = ')
input (tinggi)
volume ← panjang * lebar * tinggi;
output ('Hasil Volume = ', volume : 4 : 2, ' cm ^ 3 ');
end.
Analisis :
T(n) = cop.c(n)
* :
2
T(n) = 2a
Procedure sequential_search (input : LarikInt, input n : Integer,
input x : integer, output ketemu : boolean)
Deklarasi :
i :
integer;
Algoritma :
i ← i
+ 1
while
(i < n) and (L[i] <>
x) do
i ← i + 1
endwhile
if
L[i] = x then
ketemu ← true
else
ketemu ← false
endProcedure.
Analisis :
T(n) = cop.c(n)
← :
2 + (n - 1)
+ : 1 + (n - 1)
< : n
<> : n
= : 1
T(n) = (2 + (n - 1))a + (1 + (n - 1))b + nc + nd
+ e
T(1) = 2a + b + c + d + e
0 komentar:
Post a Comment