COP 2220 Assignment 5

$30.00

Download Details:

  • Name: Assignment5-cvednk.zip
  • Type: zip
  • Size: 1.24 MB

Category:

Description

5/5 - (1 vote)

For any integer n > 0, n!(n factorial) is defined as the product
n * n – 1 * n − 2 … * 2 * 1.
And 0! is defined to be 1.
It is sometimes useful to have a closed-form definition instead; for this purpose, an approximation can be
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.
TIP: Be careful with the type conversions. Be sure to use a named constant for PI, and use the
approximation 3.14159265.
Each section is worth 25 points for a total of 100 points.