Advertisement
labyyysosaaat

Untitled

Oct 14th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <locale>
  3. #include <cmath>
  4. using namespace std;
  5. unsigned long long factorial(int n) {
  6. return (n == 1 || n == 0) ? 1 : factorial(n - 1)*n;
  7. }
  8. int main()
  9. {
  10. setlocale(LC_ALL, "Russian");
  11. double eps;
  12. cin >> eps;
  13. double x = (double)rand() / rand();
  14. cout << "x= " << x << endl;
  15. double acc = 1, cur;
  16. for (int i = 1; abs(acc - cur) - eps > 0; i++) {
  17. acc = cur;
  18. double my_sin = pow(-1, i - 1)*pow(x, 2 * i - 1) / factorial(2 * i - 1);
  19. cur = acc + my_sin;
  20. }
  21. cout << "Мой ответ: " << acc << endl;
  22. cout << "Стандартная функцция sin(x): " << sin(x) << endl;
  23. cout << "Разница: " << sin(x) - acc << endl;
  24.  
  25. system("pause");
  26. return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement