Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function factorial($n){
- return ($n == 1 || $n == 0) ? 1 : factorial($n - 1) * $n;
- }
- // Test
- //2! = 2.1 = 2
- echo factorial(2);
- //3! = 3.2.1 = 6
- echo factorial(3);
- //4! = 4.3.2.1 = 24
- echo factorial(4);
- //5! = 5.4.3.2.1 = 120
- echo factorial(5);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement