I have a code that find n factorial:
$n = 5; $factorial = 1; function fact($n) { for ($i = 1; $i <= $n; $i++) { $factorial *= $i; } } echo $factorial;
but, how can I find the ratio of the factorials of two numbers (N! / M!)
?
Advertisement
Answer
You can add a return in you function and call her 2 times:
$n = 5; $m = 2; function fact(Int $n) : Int{ $factorial = 1; for ($i = 1; $i <= $n; $i++) { $factorial *= $i; } return $factorial; } $factorialOfTwoNumbers = fact($n) / fact($m);