Advertisement
labyyysosaaat

Untitled

Oct 14th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <ctime>
  4. #include <cstdlib>
  5. using namespace std;
  6. unsigned long long factorial(int n) {
  7. return (n == 1 || n == 0) ? 1 : factorial(n - 1)*n;
  8. }
  9. int main()
  10. {
  11. srand(time(NULL));
  12. double eps;
  13. cout << "Enter epsilon: ";
  14. cin >> eps;
  15. double x =30 - rand() %60;
  16. cout << "x = " << x << endl;
  17. double slag = x;
  18. double cur = 0;
  19. int sch = 2;
  20. /*for (int i = 1; abs(acc - cur) - eps > 0; i++) {
  21. acc = cur;
  22. double my_sin = pow(-1, i - 1)*pow(x, 2 * i - 1) / factorial(2 * i - 1);
  23. cur = acc + my_sin;
  24. }*/
  25. while (abs(slag) > eps) {
  26. cur = cur + slag;
  27. slag = slag * ((-1*x*x) / (sch*(sch + 1)));
  28. sch = sch + 2;
  29. }
  30. cur = trunc(cur / eps) * eps;
  31. cout << "My answer: " << cur << endl;
  32. cout << "Standart sin(x): " << trunc(sin(x) / eps) * eps << endl;
  33. cout << "Difference: " << sin(x) - cur << endl;
  34.  
  35. system("pause");
  36. return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement