Home
Answered Questions
Computer Science
CS 153 Program 4 - Stirling Approximation (separate Compilation) 1. Write A Pure Function Double Fac

program in C. please paste code, thanks!

CS 153 Program 4 - Stirling Approximation (separate compilation) 1. Write a pure function double factoriallint Ni that computes N! N 1023°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 atining in Ni that uses the Stirling approximation to compute: approx[e!) - V22) In this formula, n is an integer, and e is base of the natural logarithm. Use the pre-processor constants from math.h: ME and M_PL Don't even dream of typing in your own literals, . Write your own function de la myPon (double x, int that computes Do this in a counting loop. Don't use the library function powil. Assume that n is a non-negative integer. Use your function Pow(in your function for the Stirling approximation. Put all three functions in a source file atirling Fun.c. This file will need some include files at the top. Except for debugging, don't have main) in this file 2. Create a header file still marun.ls that contains prototypes for three functions 3. Write a main function that asks the user for N, and then writes out a table forn from 1 to N where each line hasnt, and the Stirling approximation ton! Of course, for fairly small, will overflow. Put main in a source file called stirlingen. 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:\CSourcege string Puno stilingain. n! Approx. 0.0000 1307674368000 1300430722199.4680 Use ANSI-C syntax Compile and run using the goc environment. Do not mix tabs and spaces in the source file. Debug thoroughly. Turn in three source files named as above using Blackboard.
1. Write a pure function double factoriallint Ni that computes NI | IN = 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 stilling iint N that uses the Stirling approximation to compute: approx(n!) - V2m @ In this formula, n is an integer, and e is base of the natural logarithm. Use the pre-processor constants from math.h: ME, and MPI Dont even dream of typing in your own literals. Write your own function double wypowidouble int n) that computes Do this in a counting loop. Don't use the library function pow . Assume that n is a non-negative integer. Use your function my ow) in your function for the Stirling approximation. Put all three functions in a source file stiring . This file will need some include Tiles at the top. Except for debugging, don't have an in this file 2. Create a header file stirlingfun.h that contains prototypes for three functions 3. Write a main function that asks the user for N, and then writes out a table forn from 1 to N where each line has nnt, and the Stirling approximation ton! Of course, for fairly small, nt will overflow Put main in a source file called strings. 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:\Sourcece string Fun.c stirlingtain.c Colour Enter -->15 0.0000 0.9221 5.362 23.3062 39902.3955 39916800 479001600 6227020800 87178291200 130767436B000 3598695.6187 39615525.0306 475687486.4728 6187239475. 1927 B6661001740.5988 1300430722199.4680 Use ANSI-C syntax, Compile and run using the gcc environment. Do not mix tabs and spaces in the source file. Debug thoroughly. Turn in three source files named as above using Blackboard.

Code :- stirlingFun.h double myPow(double x,int n); double factorial(int N); double stirling(int N); stirlingFun.c #include