Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- double factorial(double num){
- if(num < 0)
- return 0;
- if (num == 0)
- return 1;
- else
- return num * factorial(num - 1);
- }
- double Calc(double x, double epsilon) {
- double res, a;
- a = x;
- res = a;
- int i = 1;
- do {
- a = a*(-1*(pow(x,2)*factorial(2*i+1))/factorial(2*i+3));
- res += a;
- i++;
- } while (abs(a) >= epsilon);
- return res;
- }
- int main()
- {
- double x, e, n;
- cin >> x >> e;
- n = Calc(x,e);
- cout << n;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement