-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrime_Number.php
More file actions
31 lines (26 loc) · 880 Bytes
/
Prime_Number.php
File metadata and controls
31 lines (26 loc) · 880 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
<?php
/**
* Program: Prime Number Checker
* Description: Checks whether a given number is prime or not.
*/
$number = 17;
$isPrime = true;
echo "<h2>Prime Number Checker</h2>";
echo "Number to check: <strong>$number</strong><br><br>";
if ($number <= 1) {
$isPrime = false;
} else {
for ($i = 2; $i <= sqrt($number); $i++) {
if ($number % $i == 0) {
$isPrime = false;
break;
}
}
}
if ($isPrime) {
echo "<span style='padding: 5px 10px; background: #238636; color: white; border-radius: 4px;'>$number is a PRIME number</span>";
} else {
echo "<span style='padding: 5px 10px; background: #da3633; color: white; border-radius: 4px;'>$number is NOT a prime number</span>";
}
echo "<br><br><em>Definition: A prime number is a natural number greater than 1 that is not a product of two smaller natural numbers.</em>";
?>