+ 1

Factorial

How to calculate the double factorial? C++

19th Feb 2022, 8:47 PM
Виктория Федяй
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
20th Feb 2022, 5:23 PM
the ice
the ice - avatar
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."
19th Feb 2022, 10:03 PM
HungryTradie
HungryTradie - avatar
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.
19th Feb 2022, 10:04 PM
HungryTradie
HungryTradie - avatar