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

Leave a Reply

Related Posts: You may like

Find Armstrong Number

Write a PHP program to Print table of Number

Write a PHP program to print prime number

Write a PHP program to print number is Even or Odd

PHPKIDA Offering Free Tools:

INSTA DOWNLOADER

Download Instagram Videos & Photos.

Download Now

CURRENCY CONVERTER

Real Time Currency Converter

Convert Now

ROBOST.TXT GEN.

Robots.txt File Creater

Create Now

HTML MINIFIER

Compress yout HTML Code

Minify Now

CSS MINIFIER

Compress yout CSS Code

Minify Now

JAVASCRIPT MINIFIER

Compress yout JavaScript Code

Minify Now

Sign up for weekly update

Milkshake is almost ready. If you're interested in testing it out, then sign up below to get exclusive access.