Posted by: JakartaTraveller.com | August 23, 2010

Algoritma Untuk Mencari Bilangan Prima

hehe berhubung kemaren iseng ngasih tugas ke adik kelas buat nyari bilangan 
prima.. n mereka dah banyak yg nyerah heheh nih ane kasih scriptnya.. 
tolong dimanfaatkan sebaik mungkin hehe :)

<?
 $batas = 100;
 $bil = '2';
 for($i=3;$i<=$batas;$i++){
 $prima = true;
 for($a=2;$a<$i;$a++){           
 if($i % $a == 0){
 $prima = false;
 break;
 }
 }
 if($prima){
 $bil = $bil . ', ' . $i;
 }
 }   
 echo($bil);
 ?>

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

Categories

%d bloggers like this: