fork(1) download
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4.  
  5. int main() {
  6. double E = 1e-1;
  7. double x = -1;
  8. double sum = 0.0;
  9. for(int i = 2; fabs(x) > E ; i++){
  10. sum += x;
  11. //cout << x << " " ;
  12.  
  13. x *= (-1./i);
  14.  
  15. }
  16. cout << sum;
  17. return 0;
  18. }
Success #stdin #stdout 0s 3456KB
stdin
 
stdout
-0.666667