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. for(m=2; m<N; m++){
  16. d=1.0/m;
  17. s=0;
  18. for(a=0; a<m; a++){
  19. s+=(f(a*d)+f((a+1.0)*d))*d/2.0;
  20. }
  21. a=sqrt(2.0);
  22. e=sqrt((s-tru)*(s-tru));
  23. printf("%f\t%f\n",m,e);
  24. }
  25. }
Success #stdin #stdout 0s 5284KB
stdin
 4*integrate(sqrt(2*x-x*x)-1/2, x,1-sqrt(3/4),1/2); 
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