Why do you keep multiplicating random values with the faculty of 23?
Just assign the right values to some variables, replace ! with fac (you need to create that function yourself) and ^ with pow. There's your C++ code.
this means you don't have to calculate massive upper and lower numbers which might overflow
what about q^(n-x) here you might get underflow.
The product accumulating in this loop gets bigger and bigger, so maybe if you sometimes multiply the accumulating product by q (so as to get the right number of q's then you can avoid the underflow.
In Excel are you using some inbuilt function like BINOMIAL or something?
Well, if you believe that formula makes sense (it doesn't), then how about doing what Disch said?
But if you want the real result, you'd better stick to the original formula you posted, with n=46 and p=1.0/12.
That's not the faculty, but it is the solution to Comb(23, 1). Just look at the structure of the faculty calculation: 1*2*3*....*n. That's a perfect candidate for a for loop.
(Do note: I think overflows will happen around 15!. Hence why mik2718 gave the Comb() function rather than the faculty).
As Athar has said there is actually plenty of headroom for calculating this particular problem using factorials.
double precision goes up to ~1.7x10^308
I make it that you can calculate factorials up to 170! ~ 7.25742e+306
Using the method I've shown you can do better, for instance if you wanted to do 200 choose 1, then using factorials you would come unstuck.
Which made me realize that the function could be improved upon since 200 choose 1 is the same as 200 choose 199, so by choosing the smallest of x or n-x for the number of iterations you could speed up the calculation.
@peter, I think you have put a wrong formula into Excel and got a wrong answer, which could not be replicated in C++ which does not have an in-built factorial function. Probably best to go back to the formula and get the maths right.