-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfactorial.php
More file actions
33 lines (28 loc) · 767 Bytes
/
Copy pathfactorial.php
File metadata and controls
33 lines (28 loc) · 767 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
<!DOCTYPE html>
<html>
<head>
<title>Factorial of a Number</title>
</head>
<body>
<h2>Factorial Calculator</h2>
<form method="post">
<label>Enter a number:</label>
<input type="number" name="num" required>
<input type="submit" name="submit" value="Find Factorial">
</form>
<?php
if (isset($_POST['submit'])) {
$num = $_POST['num'];
if ($num < 0) {
echo "<p style='color:red;'>Factorial is not defined for negative numbers.</p>";
} else {
$fact = 1;
for ($i = 1; $i <= $num; $i++) {
$fact *= $i;
}
echo "<h3>Factorial of $num is: $fact</h3>";
}
}
?>
</body>
</html>