fork download
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <math.h>
  5.  
  6. float Series(float x, unsigned int N)
  7. {
  8. x = fmod(x,2*3.1415925358979323846);
  9. float term = x*x*x;
  10. x *= -x;
  11. float sum = term, tr = 8;
  12.  
  13. for(int n = 2; n <= N; ++n)
  14. {
  15. term /= tr;
  16. tr = (tr+1)*9-1;
  17. term *= x*tr/(2*n*(2*n+1));
  18. sum += term;
  19. }
  20. return sum;
  21. }
  22.  
  23.  
  24. int main(int argc, const char * argv[])
  25. {
  26. for(float x = 0.1; x < 1500; x = x*2)
  27. {
  28. printf("%f %f\n",Series(x,30),sin(x)*sin(x)*sin(x));
  29. }
  30. }
  31.  
Success #stdin #stdout 0s 5432KB
stdin
Standard input is empty
stdout
0.000995  0.000995
0.007841  0.007841
0.059054  0.059054
0.369151  0.369151
0.998721  0.998721
-0.000182  -0.000199
0.001583  0.001583
0.012408  0.012408
0.091394  0.091393
0.520328  0.520326
0.873323  0.873325
-0.177104  -0.177253
0.802985  0.802971
0.322481  0.322514