Programming-Idioms

History of Idiom 31 > diff from v28 to v29

Edit summary for version 29 :
Restored version 27

Version 28

2016-02-18, 16:57:58

Version 29

2016-02-18, 17:22:31

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