Advertisement
kirya_shkolnik

C++ - Никита - 3

Jan 22nd, 2021
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. double factorial(double num){
  7.     if(num < 0)
  8.         return 0;
  9.     if (num == 0)
  10.         return 1;
  11.     else
  12.         return num * factorial(num - 1);
  13. }
  14. double Calc(double x, double epsilon) {
  15.     double res, a;
  16.     a = x;
  17.     res = a;
  18.     int i = 1;
  19.     do {
  20.         a = a*(-1*(pow(x,2)*factorial(2*i+1))/factorial(2*i+3));
  21.         res += a;
  22.         i++;
  23.     } while (abs(a) >= epsilon);
  24.     return res;
  25. }
  26.  
  27. int main()
  28. {
  29.     double x, e, n;
  30.     cin >> x >> e;
  31.     n = Calc(x,e);
  32.     cout << n;
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement