Created
December 11, 2017 14:28
-
-
Save dwihujianto/e6ed95ce36f96f64ccd70a2def3782bf to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| $number = '1.345.679'; | |
| $number = str_replace('.', '', $number); | |
| $output = ''; | |
| $length = strlen($number) - 1 ; | |
| for ($i=0; $i <= $length; $i++) { | |
| $o = ''; | |
| if ($length - $i > 0) { | |
| $o = str_repeat('0', $length - $i); | |
| } | |
| $output .= $number[$i].$o."\n"; | |
| } | |
| echo($output); |
This file contains hidden or 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 | |
| if(isset($argv[1])) { | |
| print_r(fib($argv[1])); | |
| } else { | |
| echo "Masukan angka php ".$argv[0]." <Jumlah angka> "; | |
| } | |
| function fib($n) { | |
| $f1=0; | |
| $f2=1; | |
| $fibList = [0]; | |
| for ($i=0; $i<$n; $i++) { | |
| $output = $f1 + $f2; | |
| array_push($fibList, $output); | |
| $f1 = $f2; | |
| $f2 = $output; | |
| } | |
| return $fibList; | |
| } | |
This file contains hidden or 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 | |
| if(isset($argv[1])) { | |
| print_r(printPrime($argv[1])); | |
| } else { | |
| echo "Masukan angka php ".$argv[0]." <Jumlah angka> "; | |
| } | |
| function printPrime($n) { | |
| $primeList = []; | |
| for ($i=1; $i <= $n; $i++) { | |
| $counter = 0; | |
| for($x=1; $x <= $i; $x++) { | |
| if($i % $x == 0) { | |
| $counter++; | |
| } | |
| } | |
| if ($counter == 2) { | |
| $primeList[] = $i; | |
| } | |
| } | |
| return $primeList; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment