Advertisement
Derga

Untitled

Feb 27th, 2023
741
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. /*
  2. Задание 5.
  3. */
  4.  
  5. #include <cmath>
  6. #include <iomanip>
  7. #include <iostream>
  8.  
  9. using namespace std;
  10.  
  11. int main() {
  12.     double x;
  13.     double eps;
  14.     cin >> x >> eps;
  15.    
  16.     double result = x;
  17.     uint64_t i = 2;
  18.     uint64_t factorial = 1;
  19.     double val = 0;
  20.  
  21.     double cur_val = INT_MAX;
  22.     while (abs(cur_val) > eps) {
  23.         cur_val = pow(x, i) / factorial;
  24.         factorial *= i;
  25.         i++;
  26.         result += cur_val;
  27.     }
  28.  
  29.     const int PRECISION = 15;
  30.     cout << fixed << setprecision(PRECISION) << result;
  31.  
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement