Logo

Programming-Idioms

History of Idiom 31 > diff from v30 to v31

Edit summary for version 31 by :
[PHP] Updated function name

Version 30

2016-02-19, 14:58:25

Version 31

2016-02-19, 15:00:36

Idiom #31 Recursive factorial (simple)

Create recursive function f which returns the factorial of non-negative integer i, calculated from f(i-1)

Idiom #31 Recursive factorial (simple)

Create recursive function f which returns the factorial of non-negative integer i, calculated from f(i-1)

Code
function factorial($num) {
	if($num == 0) {
		return 1;
	}
	else {
		return ($num * factorial($num-1));
	}
}
Code
function f($num) {
	if($num == 0) {
		return 1;
	}
	else {
		return ($num * f($num-1));
	}
}