Answers for "Write a program to calculate and print the factorial of a number in php"

PHP
0

php program to find factorial of a number using function

<?php
function Factorial($number){ 
    if($number <= 1){   
        return 1;   
    }   
    else{   
        return $number * Factorial($number - 1);   
    }   
} 
  
$number = 5; 
$fact = Factorial($number); 
echo "Factorial = $fact";  //output : 120
?>
Posted by: Guest on March-27-2021
0

Write a program to calculate and print the factorial of a number in php

<?php $number = 4; $fact = 1; for ($x=$number; $x>=1; $x--) { $fact = $fact * $x; } echo "fact of $number is $fact"; ?>
Posted by: Guest on July-18-2021

Code answers related to "Write a program to calculate and print the factorial of a number in php"

Browse Popular Code Answers by Language