You first need to write a function that returns the factorial of a number. Be careful here because those values will grow very large very quickly. Calculating factorials in c++ programs has lots of limitations due to small numeric sizes. See limits.h for the maximum size of an integer or other numeric variables.

Once you have that, the rest should be pretty easy.