Logo

Programming-Idioms

History of Idiom 31 > diff from v65 to v66

Edit summary for version 66 by zqwnvl:
[C#] Omit modifiers; use names specified in lead

Version 65

2021-08-16, 03:47:39

Version 66

2021-08-16, 04:02:03

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)

Variables
f,i
Variables
f,i
Code
private static int Factorial(int n) {
    if (n == 0) return 1;
    return n * Factorial(n - 1);
}
Code
int f(int i)
{
    if (i == 0) return 1;
    return i * f(i - 1);
}