Double factorial - GeeksforGeeks
Double factorial of a non-negative integer n, is the product of all the integers from 1 to n that have the same parity (odd or even) as n. It is also called as semifactorial of a number and is denoted by !!. For example, double factorial of 9 is 9*7*5*3*1 which is 945. Note that, a consequence of this definition is 0!! = 1.
Read full article from Double factorial - GeeksforGeeks
Double factorial of a non-negative integer n, is the product of all the integers from 1 to n that have the same parity (odd or even) as n. It is also called as semifactorial of a number and is denoted by !!. For example, double factorial of 9 is 9*7*5*3*1 which is 945. Note that, a consequence of this definition is 0!! = 1.
unsigned
int
doublefactorial(unsigned
int
n)
{
if
(n == 0 || n==1)
return
1;
return
n*doublefactorial(n-2);
}
unsigned
int
doublefactorial(unsigned
int
n)
{
int
res = 1;
for
(
int
i=n; i>=0; i=i-2)
{
if
(i==0 || i==1)
return
res;
else
res *= i;
}
}