# Write a program find Factorial of a number

Here we are writing a program of print the factorial of a number, factorial means 1 to n multiply them where n is defined by the product of all the digits from 1 to n.

## Important Points About Factorial:

1. Factorial is denoted by n!.
2. Factorial is calculated only for positive integers(9) not for nagative integers(-2).
3. Do you know Factorial of 0 is always 1.
4. The best and simle way to calculate the factorial of a number is by using a loop or recursive method.

Here we are calculating factorial of number using two method one is using while and second using for loop.

## PHP Program to find factorial of number using while loop:

```<?php
\$num = 5;
\$factorial = 1;
while(\$num>=1)
{
\$factorial = \$factorial*\$num;
\$num--;
}
echo "Factorial of \$num is \$factorial";
?>
```

## PHP Program to find factorial of number using for loop:

```<?php
\$num = 5;
\$factorial = 1;
for (\$i=\$num; \$i>=1; \$i--)
{
\$factorial = \$factorial * \$i;
}
echo "Factorial of \$num is \$factorial";
?>
```

## PHP program to Print factorial of a number using HTML Form

```<form method="post">
<input type="text" name="number" placeholder="Enter number" />
<input type="submit" value="Submit" />
</form>

<?php
if(isset(\$_POST['number']))
{
\$num = \$_POST['number'];
\$factorial = 1;
for (\$i=\$num; \$i>=1; \$i--)
{
\$factorial = \$factorial * \$i;
}
echo "Factorial of \$num is \$factorial";
}
?>
```

Keywords:
PHP program to Print factorial of a number, find factorial of a number, calculate factorial of a number, Program for factorial of a number, Factorial Calculator n!, factorial in php, factorial of a number in php, factorial of number using for loop, factorial of number using while loop, factorial calculator, factorial list

## Crypto Currency

PHPKIDA provides free online the best real-time crypto market price, news, predictions, index with graphs & historical data for 2000+ coins including bitcoin, ethereum, & altcoins from major cryptocurrency exchanges.

## Icon Generator

PHPKIDA provides free online icon generator. Our icon generator help you to edit, modify, resize and customize icon for your website and applications. Convert to a shap you like add icon border, you can change icon border color, border size, background color, icon shadow, icons color, icon size in your own way and save it as a png image.