Tuesday, December 5, 2017

phpMyPassion

Factorial Program in PHP

The factorial of number n is multiplying given integer with the sequence of its descending positive integers. we denoted the factorial of a number n by n! in mathematics. Here I am writing factorial program in PHP..

image source : google images
Example :-

5! = 5*4*3*2*1 = 120  

7! = 7*6*5*4*3*2*1 = 5040  


Here are writing the PHP program to find a factorial of a number.


<?php
function factorial($number){
    $factorial = 1;
    for($x=$number;$x>=1;$x--){
        $factorial = $factorial*$x;
    }
    return $factorial;
}

echo 'factorial is='.factorial(11);
?>

Output :- factorial is=3,99,16,800

Using the above program you can find the factorial of any positive integer in PHP.



About Author -

Hi, I am Anil.

Welcome to my eponymous blog! I am passionate about web programming. Here you will find a huge information on web development, web design, PHP, Python, Digital Marketing and Latest technology.

Subscribe to this Blog via Email :

Note: Only a member of this blog may post a comment.