Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

program in C. please paste code, thanks! CS 153 Program 4 - Stirling Approximation (separate compilation) 1. Write a pure function double factoriallint Ni that

image text in transcribed

program in C. please paste code, thanks!

image text in transcribed

CS 153 Program 4 - Stirling Approximation (separate compilation) 1. Write a pure function double factoriallint Ni that computes N! N 10234 ... 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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Systems

Authors: Sham Navathe,Ramez Elmasri

5th Edition

B01FGJTE0Q, 978-0805317558

More Books

Students also viewed these Databases questions

Question

Determine the area and the centroid (x, y) of thearea. = 4x 4 m 4 m

Answered: 1 week ago

Question

=+2 Why are so many countries bothered by their brain drains?

Answered: 1 week ago