/* *   exp 定積分 その0 */ #include #include void main(void) { int j; int ntrial; double x0 = 0.0, y0; double s = 0.0; double h; printf("Input: Number of trials:\n"); scanf("%u", &ntrial); h=1.0/ntrial; j = 0; x0 = x0; y0 = exp(-x0); s = s + 0.5*y0; for (j = 1; j <= ntrial-1; j ++) { x0 = x0 + h; y0 = exp(-x0); s = s + y0; } j = j +1; x0 = x0 + h; y0 = exp(-x0); s = s + 0.5*y0; s = s / ntrial; printf("s = %1.6f \n", s); }