Berikut source code programnya:
1 2 3 4 5 6 7 8 9 10 11 12 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 | <?php @$bilangan = $_POST['bilangan']; ?> <!DOCTYPE html> <html> <head> <title>Menampilkan Bilangan Genap dan Ganjil</title> </head> <body> <form action="genap_ganjil.php" method="POST"> <table> <tr> <td>Input Angka</td> <td>=</td> <td><input name="bilangan" type="text" value="<?php echo $bilangan; ?>"/></td> </tr> <tr> <td><input name="submit" type="submit" value="submit"/></td> </tr> <tr> <td> <?php $bil_awal = 1; while ($bil_awal <= $bilangan) { if ($bil_awal % 2 == 0) { echo "Bilangan genap = " . $bil_awal . "<br/>"; $bil_awal++; } else { echo "Bilangan ganjil = " . $bil_awal . "<br/>"; $bil_awal++; } } ?> </td> </tr> </table> </form> </body> </html> |
Hasil akhirnya adalah sebagai berikut:
No comments:
Post a Comment