Factorial of a Number: Write a PHP function to find the factorial of a given number.

function factorial($n) {
    if ($n <= 1) {
        return 1;
    } else {
        return $n * factorial($n - 1);
    }
}

// Example usage:
$number = 5;
echo "Factorial of $number is " . factorial($number);

Related Posts

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
Artificial Intelligence