Programming-Idioms

History of Idiom 31 > diff from v31 to v32

Edit summary for version 32 :
[PHP] variable name update

Version 31

2016-02-19, 15:00:36

Version 32

2016-02-19, 15:33:27

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 f($num) {
	if($num == 0) {
		return 1;
	}
	else {
		return ($num * f($num-1));
	}
}
Code
function f($i) {
	if($i == 0) {
		return 1;
	}
	else {
		return ($i * f($i-1));
	}
}