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: n! - n"e" 2n + TT 3 a) Create a prompt that takes in n as input. b) Compute n! accurately and store the results in an appropriate variable. n! = n * (n 1) * (n - 2) c) Next, compute n! using the approximation formula and store the results in appropriate variables. d) The message displaying the result should look something like this: 5! equals approximately 119.97003 5! is 120 accurately. e) Test the program on nonnegative integers less than 10. (A type int might not accommodate overly large numbers so feel free to store the values in an unsigned int data type). Find the difference between the two results for accurateness, then compute the percent error. Is the approximation a good representation of the actual value? Use printf to display the error. Jaccurate value – approximate value| percent error = x 100 accurate value f) Ask the user if they'd like to repeat the program and allow for iterations on the program.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
For any integer n > 0, n! (n factorial) is defined as the product

\[ n \times (n - 1) \times (n - 2) \times \ldots \times 2 \times 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:

\[
n! \approx n^n e^{-n} \sqrt{ \left( 2n + \frac{1}{3} \right) \pi }
\]

a) Create a prompt that takes in n as input.

b) Compute n! accurately and store the results in an appropriate variable.

\[ n! = n \times (n - 1) \times (n - 2) \times \ldots \times 2 \times 1. \]

c) Next, compute n! using the approximation formula and store the results in appropriate variables.

d) The message displaying the result should look something like this:

```
5! equals approximately 119.97003
5! is 120 accurately.
```

e) Test the program on nonnegative integers less than 10. (A type int might not accommodate very large numbers, so feel free to store the values in an unsigned int data type). Find the difference between the two results for accurateness, then compute the percent error. Is the approximation a good representation of the actual value? Use printf to display the error.

\[
\text{percent error} = \frac{|\text{accurate value} - \text{approximate value}|}{\text{accurate value}} \times 100
\]

f) Ask the user if they’d like to repeat the program and allow for iterations on the program.
Transcribed Image Text:For any integer n > 0, n! (n factorial) is defined as the product \[ n \times (n - 1) \times (n - 2) \times \ldots \times 2 \times 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: \[ n! \approx n^n e^{-n} \sqrt{ \left( 2n + \frac{1}{3} \right) \pi } \] a) Create a prompt that takes in n as input. b) Compute n! accurately and store the results in an appropriate variable. \[ n! = n \times (n - 1) \times (n - 2) \times \ldots \times 2 \times 1. \] c) Next, compute n! using the approximation formula and store the results in appropriate variables. d) The message displaying the result should look something like this: ``` 5! equals approximately 119.97003 5! is 120 accurately. ``` e) Test the program on nonnegative integers less than 10. (A type int might not accommodate very large numbers, so feel free to store the values in an unsigned int data type). Find the difference between the two results for accurateness, then compute the percent error. Is the approximation a good representation of the actual value? Use printf to display the error. \[ \text{percent error} = \frac{|\text{accurate value} - \text{approximate value}|}{\text{accurate value}} \times 100 \] f) Ask the user if they’d like to repeat the program and allow for iterations on the program.
**Note 1:** Use a constant macro for PI and use the value of 3.14159265.

**Note 2:** Factorials grow quickly, so your compiler might not be able to store the factorial of a large number. Feel free to upgrade your variable type from a typical `int` to an `unsigned long long int`.

**Note 3:** Make sure negative numbers are avoided for factorial calculations.
Transcribed Image Text:**Note 1:** Use a constant macro for PI and use the value of 3.14159265. **Note 2:** Factorials grow quickly, so your compiler might not be able to store the factorial of a large number. Feel free to upgrade your variable type from a typical `int` to an `unsigned long long int`. **Note 3:** Make sure negative numbers are avoided for factorial calculations.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Similar questions
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY