bil_prima
Deklarasi
i,bil,b :interger
Algoritma
b←0
input(bil)
for i ←1 to bil do
if (bil mod i = 0)
then
b←b+1
endif
endfor
if b = 2
then
output(bil,”bilangan prima”)
else
output(bil,”bukan bilangan prima”)
endif
Worst case, Best case, Average case
Tmin(n) = 2
Tmax(n) = n +1
Tavg(n) = 2 + (n+1) / 2
≈ n+1 /2
≈ n
Tidak ada komentar:
Posting Komentar