fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. double szereg(double x, const int LWS = 20) {
  8. x=x-1.0;
  9. double w,s;
  10. int i;
  11. w=x;
  12. s=0;
  13. for(i=1;i<=LWS;i++){
  14. s += w/i;
  15. w *= -x;
  16. }
  17. return s;
  18. }
  19.  
  20. int main() {
  21. double x;
  22. const int width = 12;
  23. cout << fixed ;
  24. while(cin >> x) {
  25. double y1 = log(x);
  26. double y2 = szereg(x);
  27. cout << setprecision(2) << setw(5) << x << setprecision(6)
  28. << setw(width) << y1
  29. << setw(width) << y2
  30. << setw(width) << y2-y1
  31. << endl;
  32. }
  33. return 0;
  34. }
Success #stdin #stdout 0s 3276KB
stdin
1
1.2
0.8
0.9
0.5
1.5
0.9
0.1
2.0
stdout
 1.00    0.000000    0.000000    0.000000
 1.20    0.182322    0.182322   -0.000000
 0.80   -0.223144   -0.223144    0.000000
 0.90   -0.105361   -0.105361    0.000000
 0.50   -0.693147   -0.693147    0.000000
 1.50    0.405465    0.405465   -0.000000
 0.90   -0.105361   -0.105361    0.000000
 0.10   -2.302585   -2.263350    0.039235
 2.00    0.693147    0.668771   -0.024376