fork download
  1. <?php
  2.  
  3. // your code goes here
  4.  
  5. //tekaTekiTeko
  6. // 1. Harus Unsigned Int
  7. // 2. Min 20
  8. // 3. 2 % == 0 (Teka), 3 % == 0 (Teki), 5 % == 0 (Teko), Terus penggabungan kata
  9. // kalau memenuhi lebih dari 1
  10. function tekaTekiTeko(int $batas) {
  11. if ($batas < 20) {
  12. throw new Exception("Batas harus merupakan unsigned integer mulai dari 20");
  13. }
  14.  
  15. for ($x = 1; $x <= $batas; $x++) {
  16. $output = ''; // Siapkan string kosong
  17.  
  18. if ($x % 2 == 0) {
  19. $output .= 'Teka'; // Tambahkan 'Teka' jika habis dibagi 2
  20. }
  21. if ($x % 3 == 0) {
  22. $output .= 'Teki'; // Tambahkan 'Teki' jika habis dibagi 3
  23. }
  24. if ($x % 5 == 0) {
  25. $output .= 'Teko'; // Tambahkan 'Teko' jika habis dibagi 5
  26. }
  27.  
  28. // Jika $output masih kosong, berarti tidak habis dibagi 2, 3, atau 5
  29. if ($output == '') {
  30. echo $x . "\n";
  31. } else {
  32. echo $output . "\n";
  33. }
  34. }
  35. }
Success #stdin #stdout 0.02s 25852KB
stdin
tekaTekiTeko(30);
stdout
Standard output is empty