fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3. int main(void) {
  4. double a = -1000.0, b = 1000.0;
  5. int n = 100000000000000;
  6. double h = (b - a) / n;
  7. double Tm = 0.0;
  8. Tm += exp(-pow(a, 2)) / 2;
  9. for (int i = 1; i < n; i++) {
  10. double x = a + i * h;
  11. Tm += exp(-pow(x, 2));
  12. }
  13. Tm += exp(-pow(b, 2)) / 2;
  14. Tm *= h;
  15. printf("ガウス積分の近似値: %.20f\n", Tm);
  16. return 0;
  17. }
Success #stdin #stdout 4.19s 5280KB
stdin
Standard input is empty
stdout
ガウス積分の近似値: 1.77245385090458329458