Programming-Idioms

History of Idiom 31 > diff from v14 to v15

Edit summary for version 15 :

Version 14

2015-09-04, 15:56:26

Version 15

2015-09-04, 16:01:34

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
unsigned int f(unsigned int i)
{
	return i?i*f(i-1):1;
}
Code
unsigned int f(unsigned int i)
{
	return i?i*f(i-1):1;
}
Comments bubble
Overflows for i > 20 in 64bits and for i > 12 in 32bits
Comments bubble
Overflows for i>20 in 64bits and for i>12 in 32bits