<?php
function isPrime($number)
{
if ($number < 2) {
return false;
}
for ($i=2; $i<=($number / 2); $i++) {
if($number % $i == 0) {
return false;
}
}
return true;
}
?>
<form method="post">
Enter number:<input type="text" name="num">
<input type="submit" value="go" name="sub">
</form>
<?php
if(isset($_POST['sub'])) {
$number = $_POST['num'];
if(isPrime($number)==true) {
echo "<h2>$number is a prime number</h2>";
} else {
echo "<h2>$number is not a prime number</h2>";
}
}
?>
No comments:
Post a Comment