fork download
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <cmath>
  5. using namespace std;
  6. int main() {
  7. double x, eps,t,s;
  8. cout <<" x = "; cin >> x;
  9. cout << " eps = "; cin >> eps;
  10. int k = 0;
  11. t = x/2;
  12. s = t;
  13. printf("%3c%8c%8c\n", 'k', 't', 's');
  14. printf("%3d%8e%8c\n", k, t, s);
  15. while (fabs(t)> eps){
  16. k++;
  17. t*= - (pow (x,2) / (4*(k+1)));
  18. s += t;
  19. printf("%3d%8e%8.2f\n", k, t, s);
  20. }
  21.  
  22. printf("\nS=%6.3f\n", s);
  23.  
  24. return 0;
  25. }
Success #stdin #stdout 0.01s 5468KB
stdin
1 2
stdout
 x =  eps =   k       t       s
  05.000000e-01       

S= 0.500