-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathis_it_prime.php
51 lines (26 loc) · 1023 Bytes
/
is_it_prime.php
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
42
43
44
45
46
47
48
49
50
51
<?php
if(is_numeric($_GET['number']) && $_GET['number'] > 0 && $_GET['number'] == round($_GET['number'], 0)){
$i = 2;
$isPrime = true;
while ($i < $_GET['number']) {
if ($_GET['number'] % $i == 0) {
// Number is not prime!
$isPrime = false;
}
$i++;
}
if ($isPrime) {
echo "<p>".$i." is a prime number!</p>";
} else {
echo "<p>".$i." is not prime.</p>";
}
} else if ($_GET) {
// User has submitted something which is not a positive whole number
echo "<p>Please enter a positive whole number.</p>";
}
?>
<p>Please enter a whole number.</p>
<form>
<input name="number" type="text">
<input type="submit" value="Go!">
</form>