Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <locale>
- #include <cmath>
- using namespace std;
- unsigned long long factorial(int n) {
- return (n == 1 || n == 0) ? 1 : factorial(n - 1)*n;
- }
- int main()
- {
- setlocale(LC_ALL, "Russian");
- double eps;
- cin >> eps;
- double x = (double)rand() / rand();
- cout << "x= " << x << endl;
- double acc = 1, cur;
- 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;
- }
- cout << "Мой ответ: " << acc << endl;
- cout << "Стандартная функцция sin(x): " << sin(x) << endl;
- cout << "Разница: " << sin(x) - acc << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement