contoh program bilangan prima dengan menggunakan bantuan array.
Contoh program :
Program Mencari_Bilangan_Prima_Dengan_Array;
Uses Crt;
Var
Prima : Array[1..100] of Integer;
i,j : Integer;
bil : Integer;
Begin
ClrScr;
For i := 2 to 100 Do
Begin
Prima[i]:=i;
For j:= 2 to i-1 Do
Begin
bil := (i mod j); {* i dibagi j dicek apakah 0*}
If bil = 0 then Prima[i]:=0; {*jika habis dibagi,berarti bkn prima*}
End;
If Prima[i]<> 0 Then Write(Prima[i],' '); {*cetak array yg prima*}
End;
Readln;
End.
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment