-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprimeornot.php
More file actions
39 lines (34 loc) · 954 Bytes
/
Copy pathprimeornot.php
File metadata and controls
39 lines (34 loc) · 954 Bytes
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
<!DOCTYPE html>
<html>
<head>
<title>Prime Number Checker</title>
</head>
<body>
<h2>Check Whether a Number is Prime or Not</h2>
<form method="post">
<label>Enter a number:</label>
<input type="number" name="num" required>
<input type="submit" name="submit" value="Check">
</form>
<?php
if (isset($_POST['submit'])) {
$num = $_POST['num'];
if ($num <= 1) {
echo "<h3>$num is NOT a prime number.</h3>";
} else {
$isPrime = true;
for ($i = 2; $i <= sqrt($num); $i++) {
if ($num % $i == 0) {
$isPrime = false;
break;
}
}
if ($isPrime)
echo "<h3>$num is a Prime number.</h3>";
else
echo "<h3>$num is NOT a Prime number.</h3>";
}
}
?>
</body>
</html>