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 + 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) 2 * 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 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. laccurate value – approximate value| percent error = х 100 accurate value f) Ask the user if they'd like to repeat the program and allow for iterations on the program.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter15: Recursion
Section: Chapter Questions
Problem 18SA
icon
Related questions
Question
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 +
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)
2 * 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 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.
laccurate value – approximate value|
percent error =
х 100
accurate value
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 * 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 + 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) 2 * 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 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. laccurate value – approximate value| percent error = х 100 accurate value f) Ask the user if they'd like to repeat the program and allow for iterations on the program.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning