+ 1
Factorial
How to calculate the double factorial? C++
3 ответов
+ 1
double factorial(double n) {
if(n == 0) {
return 1;
} else {
if(n == 1) {
return 1;
} else {
return n * factorial(n - 1);
}
}
}
// factorial(4) = 24, factorial(0) = 1
0
I think this is the pace where my coding ability exceeds my mathematical ability....
Is Jay Matthews post representative of what you are trying to achieve? (Jay, could you dumb that down just a little for me please?) What are the commas doing?
Wikipedia: "In mathematics, the double factorial or semifactorial of a number n, denoted by n‼, is the product of all the integers from 1 up to n that have the same parity (odd or even) as n."
0
So you need to check n%2, then do an {edit:not addition} multiplication algorithm with only odd(or even) numbers up to n.