a!(a+b)!

Hi!
I am struggling to write a program in C++ which evaluates a!(a+b)! for integers a and b? Can someone help please!
Last edited on
I understand how to do it for just a! but for this example would i have to implement 2 for loops? a for loop within a for loop?
I would make a factorial function and just call it twice:
factorial(a)*factorial(a+b)
oh okay, thanks! I'll give that a go!
if you think a little, you realize that (a+b)! is a!*(a+1)*...*(a+b). So I would use the iter_factorial, but change the function to take two parameters,a and b, then in the loop check if i>a. If not, ret*=(i*i), else ret*=i. Or you can do a loop to a, and a loop from a+1 to b
This doesn't seem to be too different from getting factorial of just a. For example, if a is 3 and b is 2, you'd be calculating the factorial of their sum, or 6? and then multiplying it by the factorial of just a?

If you have a function that will calculate a factorial, I'd call the function twice, once for a, then for a+b, then multiply the results, keeping in mind that factorials can get very large pretty quickly.


Edit: ninja'd while typing too slowly
Last edited on
Thanks. I'm fairly new to C++. I've just started teaching myself recently. All of your help is much appreciated! :)
Topic archived. No new replies allowed.