Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F99376709
pi_mc.c
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Jan 24, 00:16
Size
615 B
Mime Type
text/x-c
Expires
Sun, Jan 26, 00:16 (1 d, 20 h)
Engine
blob
Format
Raw Data
Handle
23786877
Attached To
rSCEXAMPLES SCITAS examples on how to run on the clusters
pi_mc.c
View Options
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#define SEED 35791246
int main(int argc, char* argv)
{
int niter=0;
double x,y;
int i,count=0; /* # of points in the 1st quadrant of unit circle */
double z;
double pi;
niter=99999999;
/* initialize random numbers */
srand(SEED);
count=0;
for ( i=0; i<niter; i++) {
x = (double)rand()/RAND_MAX;
y = (double)rand()/RAND_MAX;
z = x*x+y*y;
if (z<=1) count++;
}
pi=(double)count/niter*4;
printf("# of trials= %d , estimate of pi is %g \n",niter,pi);
exit (0);
}
Event Timeline
Log In to Comment