Question: For any integer n > 0, n!(n factorial) is defined as the product n * n - 1 * n 2 ... * 2 *

For any integer n > 0, n!(n factorial) is defined as the product

n * n - 1 * n 2 ... * 2 * 1. It is sometimes useful to have a closed-form definition instead; for this purpose, an approximation can be

And 0! is defined to be 1. used. R.W. Gosper proposed the following approximation formula:

a) Create a function takes n as input and returns the approximation for factorial value back.

b) Create another function takes n as input and computes then returns the accurate value for n!=

n * n - 1 * n 2 ... * 2 * 1.

c) Your program should prompt the user to enter an integer n, call both functions to compute the approximate and accurate values for n! and then display the results. The message displaying the result should look something like this:

5! equals approximately 119.97003 5! is 120 accurately.

d) Test the program on nonnegative integers less than 8, and also on integers greater than 8. At what value does the approximation fail to generate accurate results? Generate a message that reports if the approximation is not valid anymore.Use the percent error formula to find if the approximation value is accurate.

TIP: Be careful with the type conversions. Be sure to use a named constant for PI, and use the approximation 3.14159265.

percent error

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!