<?php
function fatorial($num) {
if ($num == 0) {
return 1;
} else {
return $num * fatorial($num -1);
}
}
echo "Digite um numero qeu voce deseja saber o fatorial: ";
$n = intval(trim(fgets(STDIN)));
if ($n >= 0) {
$resultado = fatorial($n);
echo "\nO fatorial do numero $n eh $resultado\n";
} else {
echo "\nNao existe fatorial de numeros negativos!\n";
}
?>
To embed this project on your website, copy the following code and paste it into your website's HTML: