Skip to content

Mencari bilangan Prima dengan array di Pascal

May 24, 2011

Nie bagi yang masih pengen belajar pascal atau merefresh tentang pascal nie gue punya coding tentang pascal yang mencari bilngan prima menggunakan array mw tw???Nie dia codingnya:

Program Mencari_Bilangan_Prima_Dengan_Array;
Uses Crt;
Var
  Prima : Array[1..200] of Integer;
  i,j : Integer;
  bil : Integer;
Begin
  ClrScr;
  For i := 2 to 200 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.

nah nie dia codingnya nie akan menampilkan bilangan prima antara 1 mpe 200 . . .

met coba bro . . .

About these ads
No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: