Advertisement
Guest User

Untitled

a guest
Oct 28th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4.  
  5. int main()
  6. {
  7.     auto x{ 0.0 },
  8.         e{ 0.0 };
  9.     auto n{ 3 };
  10.    
  11.     std::cin >> x >> e;
  12.  
  13.     auto yr{ x }, yr2{ std::pow(x, n) / n };
  14.     auto sum{ 0.0 };
  15.  
  16.     while (std::abs(yr2 - yr) >= e)
  17.     {
  18.         sum += yr;
  19.        
  20.         yr = yr2;
  21.  
  22.         n += 2;
  23.  
  24.         yr2 = std::pow(x, n) / n;
  25.     }
  26.    
  27.     std::cout << std::fixed << std::setprecision(6) << sum;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement