fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int N, k=1;
  6. double S=1.;
  7.  
  8. cout << "N="; cin >> N;
  9.  
  10. for (int i = 1; i < N; i++)
  11. {
  12. k*=-2;
  13. S+=1./k;
  14. }
  15.  
  16. cout << "S=" << S << "\n";
  17. return 0;
  18. system("pause");
  19. }
Success #stdin #stdout 0.01s 5532KB
stdin
Standard input is empty
stdout
N=S=inf