fork download
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <math.h>
  5.  
  6. double sum(double x, double eps)
  7. {
  8. double s = x, t = x;
  9. x *= x;
  10. for(int n = 1; fabs(t) > eps; ++n)
  11. {
  12. s += t *= -x/(2.*n*(2.*n+1));
  13. }
  14. return s;
  15. }
  16.  
  17. int main(int argc, const char * argv[])
  18. {
  19. for(double x = 0.0; x < 1.0; x += 0.1)
  20. {
  21. printf("%3.1lf %12.9lf %12.9lf\n",
  22. x,sin(x),sum(x,1e-7));
  23. }
  24. }
  25.  
Success #stdin #stdout 0s 9424KB
stdin
Standard input is empty
stdout
0.0   0.000000000    0.000000000
0.1   0.099833417    0.099833417
0.2   0.198669331    0.198669331
0.3   0.295520207    0.295520207
0.4   0.389418342    0.389418342
0.5   0.479425539    0.479425539
0.6   0.564642473    0.564642473
0.7   0.644217687    0.644217687
0.8   0.717356091    0.717356091
0.9   0.783326910    0.783326910
1.0   0.841470985    0.841470985