fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6. float sl = 1;
  7. float s=0;
  8. float e=0.00005;
  9. int k=1;
  10. while (sl>=e)
  11. {if (k%2==0){s+=sl;}
  12. else
  13. {s-=sl;}
  14. k++;
  15. sl/=k;
  16. }
  17. cout << s;
  18. return 0;
  19. }
Success #stdin #stdout 0.01s 2680KB
stdin
Standard input is empty
stdout
-0.632143