Created
April 25, 2016 04:16
-
-
Save 3Shoka/07fdd53b263cbcb606c60a4c3f01d1bb to your computer and use it in GitHub Desktop.
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 | |
# n = (n+1)*(n-1) | |
# dapatkan nilai ganjil genap dan prima | |
# jumlah masing masing jika deretnya 100 | |
# ganjil (23): x, y, z | |
# genap (77): a, b, c | |
# prima ((7)): g, h, i | |
for($i=1;$i<=100;$i++){ | |
$angka = ($i+1)*($i-1); | |
echo $angka; | |
echo ','; | |
if($angka%2==1){ | |
$ganjil[] = $angka; | |
} | |
if($angka%2==0){ | |
$genap[] = $angka; | |
} | |
$p=0; | |
for($j=1;$j<=$angka;$j++){ | |
if($angka%$j==0){ | |
$p++; | |
} | |
} | |
if($p==2){ | |
$prima[] = $angka; | |
} | |
} | |
echo PHP_EOL; | |
echo 'ganjil ('.count($ganjil).'): '; | |
// print_r($ganjil); | |
while(list($key, $val)= each($ganjil)) echo $val.','; | |
echo PHP_EOL; | |
echo 'genap ('.count($genap).'): '; | |
// print_r($genap); | |
while(list($key, $val)= each($genap)) echo $val.','; | |
echo PHP_EOL; | |
echo 'prima ('.count($prima).'): '; | |
// print_r($prima); | |
while(list($key, $val)= each($prima)) echo $val.','; | |
echo PHP_EOL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment