Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Accounting questions