Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <ctime>
- #include <cstdlib>
- using namespace std;
- unsigned long long factorial(int n) {
- return (n == 1 || n == 0) ? 1 : factorial(n - 1)*n;
- }
- int main()
- {
- srand(time(NULL));
- double eps;
- cout << "Enter epsilon: ";
- cin >> eps;
- double x =30 - rand() %60;
- cout << "x = " << x << endl;
- double slag = x;
- double cur = 0;
- int sch = 2;
- /*for (int i = 1; abs(acc - cur) - eps > 0; i++) {
- acc = cur;
- double my_sin = pow(-1, i - 1)*pow(x, 2 * i - 1) / factorial(2 * i - 1);
- cur = acc + my_sin;
- }*/
- while (abs(slag) > eps) {
- cur = cur + slag;
- slag = slag * ((-1*x*x) / (sch*(sch + 1)));
- sch = sch + 2;
- }
- cur = trunc(cur / eps) * eps;
- cout << "My answer: " << cur << endl;
- cout << "Standart sin(x): " << trunc(sin(x) / eps) * eps << endl;
- cout << "Difference: " << sin(x) - cur << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement