Created
March 17, 2017 06:45
-
-
Save uyab/27a6ea425bab05df62173eef13de5d6e to your computer and use it in GitHub Desktop.
Print Bilangan Prima
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function isPrime($number) { | |
if($number <= 1) { | |
return false; | |
} | |
foreach(range(2, $number) as $i) { | |
if($number % $i == 0) { | |
if($i != $number) { | |
return false; | |
} | |
} | |
} | |
return true; | |
} | |
echo "List Bilangan Prima s/d 100:<br>"; | |
foreach(range(1, 100) as $i) { | |
if(isPrime($i)) { | |
echo $i.'<br>'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment