66. PHP Program to find the Factorial of a given number.
How does this program work?
- This program is used to find the factorial of a given number using PHP.
- Factorial number is defined by the product of all the digits of given number.
- Factorial of 0 is always 1.
Here is the code
<html>
<head>
<title>PHP Program To find the Factorial of a given number</title>
</head>
<body>
<form method="post">
<table border="0">
<tr>
<td> <input type="text" name="num" value="" placeholder="Enter a number"/> </td>
</tr>
<tr>
<td> <input type="submit" name="submit" value="Submit"/> </td>
</tr>
</table>
</form>
<?php
if(isset($_POST['submit']))
{
$n = $_POST['num'];
$factorial = 1;
for ($i = 1; $i <= $n; $i++)
{
$factorial = $factorial * $i;
}
echo "Factorial of number ". $n . " is: " .$factorial;
return 0;
}
?>
</body>
</html>