fork download
  1. #include<stdio.h>
  2. #include<math.h>
  3. #define N 20
  4.  
  5. float f(float x)
  6. {
  7. return(x*x);
  8. }
  9.  
  10. int main()
  11. {
  12. char ch1[80];
  13. double a,d,m,n,s,tru,e;
  14. tru=1.0/3.0;
  15.  
  16. for(m=2; m<N; m++){
  17. d=1.0/m;
  18. s=0;
  19. for(a=0; a<m; a++){
  20. s+=(f(a*d)+f((a+1.0)*d))*d/2.0;
  21. }
  22. a=sqrt(2.0);
  23. e=sqrt((s-tru)*(s-tru));
  24. printf("%f\t%f\n",m,e);
  25. }
  26. }
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
2.000000	0.041667
3.000000	0.018519
4.000000	0.010417
5.000000	0.006667
6.000000	0.004630
7.000000	0.003401
8.000000	0.002604
9.000000	0.002058
10.000000	0.001667
11.000000	0.001377
12.000000	0.001157
13.000000	0.000986
14.000000	0.000850
15.000000	0.000741
16.000000	0.000651
17.000000	0.000577
18.000000	0.000514
19.000000	0.000462