Question: Example C Program to Compute Pl Using A Monte Carlo Method Source code: /* Program to compute Pi using Monte Carlo methods include include stdlib.h>

 Example C Program to Compute Pl Using A Monte Carlo Method

Example C Program to Compute Pl Using A Monte Carlo Method Source code: /* Program to compute Pi using Monte Carlo methods include include stdlib.h> stdio.h #include #define SEED 35791246 nain(int argc, char* argv) include int niter-0 double x.y int i, count0; /* # of points in the 1st quadrant of unit circle double z: double pi; printf( Enter the number of iterations used to estinate pi:) scanfd",Eniter) /initialize random numbers / srand (SEED) count-e for i-0: isniter: i+) x- y (double) rand ()/RAND MAX: (double) rand ()/RAND MAX: if (z 1) count+ pi-(double)countiter 4: print f(*# of trials= %d estimate of pi is vn..niter,pi); Monte Carlo techniques: use of random sampling techniques to solve mathematical or physical problems Command to compile and link: ce -o monte pi nonte pi.c Commands to compile and link in two steps: 1. cc-c monte-p.c (this produces object file noate_pi.o) 2.cc -o monte pi monte pi.o (produces executable monte pi) Output of command 'ls-1 monte pi':32-rwxI-T-x 1 sas user 12580 Oct 11 14:25 monte pl Output of command file monte pi: ELF N32 MSB mips-4 dymamic executable (not stripped) MIPS version 1 To run type: monte pi Results of running monte pi: azure 58% nonte_pi 3/L/2017 Sample C Program Enter the number of iterations used to estinate pi: 1000 # of trials. 1000 , estimate of pi is 3.044 Run the program using an input file Create a file called monte.input with the number interations (ex. 1000) on the first line. Issue the command monte pimonte.input To run the program monte pi in the background with an input file: te_p nonte. input&

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!