Factorial Program

factorial
PHP

Factorial Program

Write a program to find the factorial of a number.

Factorial of a number is the product of numbers from 1 to ‘n’.

Eg:- 5! = 1*2*3*4*5 = 120

PHP :-

<?php
$n = 10;
$product = 1;

for($i=1; $i<=$n; $i++)
{
    $product = $product*$i;
}
echo 'The factorial of '.$n.' is '.$product;
?>
  1. Declare the number to $n
  2. Set $product as 1
  3. In a for loop, loop through 1 to $n
  4. Inside the for loop, multiply $i with $product
  5. Print the result after closing loop

For more information visit gmp_fact.

For more php related queries visit PHP

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top