Question: Assignment For any integer n > 0 , n ! is defined as the product n n - 1 n - 2 dots 2 1

Assignment
For any integer n>0,n! is defined as the product nn-1n-2dots21.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 such
approximation formula:
n!~~nne-n(2n+13)2
Create a program that prompts the user to enter an integer n, uses Gosper's formula to approximate n!, and then displays the
result. The message displaying the result should look something like this:
5! equals approximately 119.97003
Your program will be easier to debug if you use some intermediate values instead of trying to compute the result in a single
expression. If you are not getting the correct results, then you can compare the results of your intermediate values to what you get
when you do the calculations by hand. Use at least two intermediate variables-one for
2n+13
and one for
(2n+13)2
Display each of these intermediate values to simplify debugging. Be sure to use a named constant for PI, and use the
approximation 3.14159265. Test the program on nonnegative integers less than 8.
Test Cases
n,n!
approximation
8
40315.903
Assignment For any integer n > 0 , n ! is defined

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 Programming Questions!