<?php function prime($i) { $prime = true; for($j=2;$j<=$i-1;$j++) { if($i % $j == 0) { $prime = false; break(1); } } return $prime; } if(isset($_POST['num'])) { $num = $_POST['num']; $isPrime = prime($num); if($isPrime == true) { echo "$num adalah bilangan prima"; } else { echo "$num bukan bilangan prima"; } } echo "<form method='post'>"; echo "Masukkan angka: <input type='text' name='num'>"; echo "<input type='submit'>"; echo "</form>"; ?>
Post a Comment