/* * @@ exp ϕ */ #include #include #include #define RAND() ((double)rand() / (1.0 + RAND_MAX)) void main(void) { int seed; int j; int ntrial; int n1 = 0; double x0, y0; double s; printf("Input: Number of trials:\n"); scanf("%u", &ntrial); printf("Input: seed\n"); scanf("%u", &seed); srand(seed); for (j = 1; j <= ntrial; j ++) { x0 = RAND(); y0 = RAND(); if (y0 < exp(-x0)) { n1 = n1 + 1; } } s = (double)n1 / ntrial; printf("s = %1.6f \n", s); }