Question: Write a pure function double factorial(int N) that computes N! N! = 1*2*3*4* ... *(N-1)*N Do this the obvious way by initializing a product to

Write a pure function double factorial(int N) that computes N! N! = 1*2*3*4* ... *(N-1)*N

Do this the obvious way by initializing a product to one and then multiplying the integers together using a loop. Zero factorial is defined to be one. Now write a pure function double stirling(int N) that uses the Stirling approximation to compute:

Write a pure function double factorial(int N) that computes N! N! =

In this formula, n is an integer, and e is base of the natural logarithm. Use the pre-processor constants from math.h: M_E, and M_PI. Dont even dream of typing in your own literals.

Write your own function double myPow(double x, int n) that computes xn. Do this in a counting loop. Dont use the library function pow(). Assume that n is a non-negative integer. Use your function myPow() in your function for the Stirling approximation.

Put all three functions in a source file stirlingFun.c. This file will need some include files at the top. Except for debugging, dont have main() in this file.

Create a header file stirlingFun.h that contains prototypes for three functions.

Write a main function that asks the user for N, and then writes out a table for n from 1 to N where each line has n, n!, and the Stirling approximation to n! Of course, for fairly small n, n! will overflow.

Put main in a source file called stirlingMain.c. This file will need appropriate header files, including the one from above. Your three files should all be in the same subdirectory.

Try to make the output look reasonably neat at least for small values of N. You will need to fiddle with formats with printf.

Compile your files and link them together using

C:\CSource>gcc strlingFun.c stirlingMain.c C:\CSource>a Enter N -->15

1*2*3*4* ... *(N-1)*N Do this the obvious way by initializing a product

Use ANSI-C syntax. Compile and run using the gcc environment. Do not mix tabs and spaces in the source file. Debug thoroughly.

approx(n!) = V2nn () n! - - -----+--------- -----+------ WNEO 5 approx. ------- 0.0000 0.9221 1.9190 5.8362 23.5062 118.0192 710.0782 4980.3958 39902.3955 359536.8728 3598695.6187 39615625.0506 475687486.4728 6187239475.1927 86661001740.5988 1300430722199.4680 24 120 720 5040 40320 362880 3628800 39916800 479001600 6227020800 87178291200 1307674368000 WNPOO OO O 15

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