fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. double f(double x){
  5. return exp(-x*x);
  6. }
  7.  
  8. int main(void) {
  9. double Tm,L=5,h,ci;
  10. int i,No,m;
  11.  
  12. for(No=1;No<100;No++){
  13. Tm=0;
  14. m=No;
  15. ci=-L+h;
  16. h=2*L/m;
  17. Tm=(f(-L)+f(L))/2;
  18. for(i=1;i<m;i++){
  19. Tm+=f(ci);
  20. ci+=h;
  21. }
  22. Tm*=h;
  23. printf("%8d %.12lf\n",No,Tm);
  24. }
  25. return 0;
  26. }
Success #stdin #stdout 0s 5280KB
stdin
Standard input is empty
stdout
       1 0.000000000139
       2 0.000000000139
       3 3.333383151175
       4 1.403858144935
       5 1.772270493802
       6 1.803821883677
       7 1.758384277114
       8 1.776445872197
       9 1.771608231330
      10 1.772594308126
      11 1.772435181852
      12 1.772455856461
      13 1.772453675799
      14 1.772453863355
      15 1.772453850170
      16 1.772453850930
      17 1.772453850895
      18 1.772453850897
      19 1.772453850898
      20 1.772453850898
      21 1.772453850898
      22 1.772453850899
      23 1.772453850899
      24 1.772453850899
      25 1.772453850900
      26 1.772453850900
      27 1.772453850900
      28 1.772453850900
      29 1.772453850900
      30 1.772453850901
      31 1.772453850901
      32 1.772453850901
      33 1.772453850901
      34 1.772453850901
      35 1.772453850901
      36 1.772453850901
      37 1.772453850901
      38 1.772453850901
      39 1.772453850901
      40 1.772453850901
      41 1.772453850902
      42 1.772453850902
      43 1.772453850902
      44 1.772453850902
      45 1.772453850902
      46 1.772453850902
      47 1.772453850902
      48 1.772453850902
      49 1.772453850902
      50 1.772453850902
      51 1.772453850902
      52 1.772453850902
      53 1.772453850902
      54 1.772453850902
      55 1.772453850902
      56 1.772453850902
      57 1.772453850902
      58 1.772453850902
      59 1.772453850902
      60 1.772453850902
      61 1.772453850902
      62 1.772453850902
      63 1.772453850902
      64 1.772453850902
      65 1.772453850902
      66 1.772453850902
      67 1.772453850902
      68 1.772453850902
      69 1.772453850902
      70 1.772453850902
      71 1.772453850902
      72 1.772453850902
      73 1.772453850902
      74 1.772453850902
      75 1.772453850902
      76 1.772453850902
      77 1.772453850902
      78 1.772453850902
      79 1.772453850902
      80 1.772453850902
      81 1.772453850902
      82 1.772453850902
      83 1.772453850902
      84 1.772453850902
      85 1.772453850902
      86 1.772453850902
      87 1.772453850902
      88 1.772453850902
      89 1.772453850903
      90 1.772453850903
      91 1.772453850903
      92 1.772453850903
      93 1.772453850903
      94 1.772453850903
      95 1.772453850903
      96 1.772453850903
      97 1.772453850903
      98 1.772453850903
      99 1.772453850903