a4p3(introprog1620 perry)

a4p3(introprog1620 perry) - c2 = (r2 < 0.85); c3...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
#include<stdio.h> #include<stdlib.h> #include<time.h> #define Ntrials 5000 double randy(void) { return rand()/(RAND_MAX + 1.0); /* 0 <= ret value <1.0*/ } int main(void) { double r1, r2, r3, p; int c1, c2, c3, success = 0, i; for( i = 0; i<Ntrials; ++i) { r1 = randy(); r2 = randy(); r3 = randy(); c1 = (r1 < 0.8); /* if (r1 < 0.6) c1 = 1; else c1 = 0; */
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: c2 = (r2 &lt; 0.85); c3 = (r3 &lt; 0.95); if(c1 &amp;&amp; (c2 || c3) ) ++success; /* output = .4818 (about) */ } p = success; p /= Ntrials; printf(&quot;p = %g\n&quot;, p); return 0; } /*two end points and subtract for randy times o.6a tiems randy */...
View Full Document

Ask a homework question - tutors are online