fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. #define EPSILON 1.0e-8
  5. int main() {
  6. double sum, term;
  7. int p, i;
  8. p = 1;
  9. sum = 1.0;
  10. for (i = 1;; i++) {
  11. /* break-condition */
  12. if ((term = 1.0 / (p = p * i)) < EPSILON)
  13. break;
  14. sum += term;
  15. }
  16. printf(" +0.1234567\n");
  17. printf("result: %+.12f\n", sum);
  18. printf("exp(1) = %+.12f\n", exp(1.0));
  19. printf("diff: %+.12f\n", sum - exp(1.0));
  20. return 0;
  21. }
  22. /* end */
Success #stdin #stdout 0.02s 1720KB
stdin
Standard input is empty
stdout
         +0.1234567
result:  +2.718281826198
exp(1) = +2.718281828459
diff:    -0.000000002261