The function
double area(int trials)
{
double x, y;
int k, hit;
hit = 0;
for(k=0; k<trials; k++) {
x = dran(1.0);
y = dran(1.0);
if (y <= exp(-x*x/2) )
hit++;
}
return (double) hit/trials;
}
This is the program
pg192.c
.
Previous slide
Next slide
Back to first slide
View graphic version