fork(1) download
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4. int main(){
  5. double sum, eps, next, A;
  6. int i=1;
  7. eps=0.001;
  8. A=-1/3.0;
  9. sum=A;
  10. while (abs(A)>eps){
  11. i=i+1;
  12. sum=sum+A;
  13. next=A*(-2)/(2*i+3);
  14. A=next;
  15. }
  16. cout << "sum="<< sum << endl << "i=" << i << endl;
  17. return 0;
  18. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
sum=-0.589266
A-6.47621e-10