Advertisement
kirya_shkolnik

Макс - 3

Jan 18th, 2021
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 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 = pow(x,5)/factorial(5);
  17.     res = a;
  18.     int i = 1;
  19.     cout << "\t" << i++ << "\t" << res << "\n";
  20.     do {
  21.         a = a*(-1*(pow(x,2)*factorial(2*i+1))/factorial(2*i+3));
  22.         res += a;
  23.         cout << "\t" << i++ << "\t" << res << "\n";
  24.     } while (abs(res-a) >= epsilon);
  25.     return res;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement