Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- long long int fact(int i)
- {
- long double fact1;
- fact1 = 1;
- for (int j = 1; j <= (2 * i - 1); j++)
- {
- fact1 *= j;
- }
- return fact1;
- /*if (i <= 1) return 1;
- else
- return i * fact(i - 1);*/
- }
- double check(void)
- {
- double value;
- while (!scanf_s("%lf", &value))
- {
- system("cls");
- rewind(stdin);
- printf("Please enter number:\n");
- }
- return value;
- }
- int main()
- {
- double e, x,summ=0;
- int i;
- printf("e=");
- e=check();
- printf("x=");
- x = check();
- for (i = 1;; i++)
- {
- summ += (pow(-1, i-1) * pow(x, (2 * i - 1))) / fact(i);
- if (abs(sin(x)-summ)<= e)
- {
- printf("\nn=%d", i);
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement