Berikut source code-nya:
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 41 | <?php @$bil_awal = $_POST['bil_awal']; @$bil_akhir = $_POST['bil_akhir']; @$hasil = 0; ?> <!DOCTYPE html> <html> <head> <title>Menjumlahkan Bilangan Ganjil</title> </head> <body> <form method="POST"> <table> <tr> <td>Input bilangan awal</td> <td>=</td> <td><input name="bil_awal" type="text" value="<?php echo $bil_awal; ?>"/></td> </tr> <tr> <td>Input bilangan akhir</td> <td>=</td> <td><input name="bil_akhir" type="text" value="<?php echo $bil_akhir; ?>"/></td> </tr> <tr> <td><input name="submit" type="submit" value="SUBMIT"/></td> </tr> </table> <?php while ($bil_awal <= $bil_akhir) { if ($bil_awal % 2 == 1) { echo $bil_awal."<br/>"; $hasil = $hasil + $bil_awal; } $bil_awal++; } echo "=====+<br/>".$hasil; ?> </form> </body> </html> |
Hasil akhirnya adalah sebagai berikut:
No comments:
Post a Comment