Logo

Programming-Idioms

History of Idiom 31 > diff from v67 to v68

Edit summary for version 68 by zqwnvl:
[C#] Add demo link

Version 67

2021-08-16, 04:08:02

Version 68

2021-08-16, 04:09:16

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
int f(int i)
{
    if (i == 0) return 1;
    return i * f(i - 1);
}
Code
int f(int i)
{
    if (i == 0) return 1;
    return i * f(i - 1);
}
Demo URL
https://sharplab.io/#gist:8a1f3dab8f99ba1e289b873b2ece11f6