The factorial of a number n (written n!) is the number times the factorial of itself minus one. This self-referential definition is easiest to understand through an example: The factorial of 2 is 2 * 1; the factorial of 3 is 3 * 2 * 1; the factorial of 4 is 4 * 3 * 2 * 1; and so on. Factorials grow very large, very quickly. An approximation to the factorial for larger values is given by Stirling’s formula:
The exp function in the <cmath> header file gives the value of e raised to given power (see Appendix C.5). We’ve already discussed all of the other functions that are needed to write this formula. Write a C++ program that computes the factorial of 15 both directly and with Stirling’s formula, and outputs both results, together with their difference. You will need to use the double type for this computation. Be sure to use proper formatting and appropriate comments in your code. The output should be labeled clearly and formatted neatly.
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.