Logo

Programming-Idioms

History of Idiom 31 > diff from v27 to v28

Edit summary for version 28 by :
[Erlang] Comments format

Version 27

2016-02-17, 18:00:11

Version 28

2016-02-18, 16:57:58

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 ) {
	if ( i == 0 ) return 1;
	
	return i * f( i - 1 )
}
Code
function F (I : Natural) return Natural is (if I < 2 then 1 else I * F (I - 1));
Code
f(0) -> 1;
f(I) -> I * f(I - 1).
Code
f(0) -> 1;
f(I) -> I * f(I - 1).
Comments bubble
No "defensive programming" here.
Comments bubble
No "defensive programming" here.
Demo URL
http://tryerl.seriyps.ru/#id=0cf3
Demo URL
http://tryerl.seriyps.ru/#id=0cf3