Advertisement
nugrohoe_ku

Quiz

May 31st, 2015
510
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.52 KB | None | 0 0
  1. <?php
  2. //Jawaban Soal 1
  3. $x = 0;
  4. while(++$x <= 100)
  5. echo($x!=8 && $x!=9 && $x!=10 && $x!=12)?"$x,":"";
  6. /*Output
  7. 1,2,3,4,5,6,7,11,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,
  8. */
  9. ?>
  10. <br />
  11. <br />
  12.  
  13. <?php
  14. //Jawaban Soal 2
  15. $nama = array("Anto","Hilmi","Khafindi","Faris");
  16. $rumah = array("Mlonggo","Bugel","Margoyoso","Wanusobo");
  17.  
  18. echo "Nama = "; foreach ($nama as $value) {
  19. print "$value, ";
  20. }
  21.  
  22. echo " <br /><br />Rumah " .$nama[1]. " ada di " .$rumah[1]. "<br /><br />";
  23.  
  24. echo "Rumah = <br />";
  25. for ($x=0;$x<4;$x++)
  26. {  
  27.     print "$nama[$x] : $rumah[$x] <br />";
  28. }
  29. /*Output
  30. Nama = Anto, Hilmi, Khafindi, Faris,
  31.  
  32. Rumah Hilmi ada di Bugel
  33.  
  34. Rumah =
  35. Anto : Mlonggo
  36. Hilmi : Bugel
  37. Khafindi : Margoyoso
  38. Faris : Wanusobo
  39. */
  40. ?>
  41. <br />
  42. <br />
  43.  
  44. <?php
  45. //Jawaban Soal 3
  46. function tampil_angka($param1,$param2) {
  47. for ($i = 1; $i <= $param1; $i++) {
  48. if (in_array($i, $param2)) continue;
  49. echo $i . ',';
  50. }
  51. }
  52. tampil_angka('100',array(8,9,10,12));
  53. /*Output
  54. 1,2,3,4,5,6,7,11,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,*/
  55. ?>
  56. <?php
  57. //Script By Bastomi Adi Nugroho @UNISNU JEPARA TIF
  58. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement