Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. long long int fact(int i)
  4. {
  5. long double fact1;
  6. fact1 = 1;
  7. for (int j = 1; j <= (2 * i - 1); j++)
  8. {
  9. fact1 *= j;
  10. }
  11. return fact1;
  12. /*if (i <= 1) return 1;
  13. else
  14. return i * fact(i - 1);*/
  15. }
  16. double check(void)
  17. {
  18. double value;
  19. while (!scanf_s("%lf", &value))
  20. {
  21. system("cls");
  22. rewind(stdin);
  23. printf("Please enter number:\n");
  24.  
  25. }
  26. return value;
  27. }
  28. int main()
  29. {
  30. double e, x,summ=0;
  31. int i;
  32.  
  33. printf("e=");
  34. e=check();
  35. printf("x=");
  36. x = check();
  37.  
  38.  
  39. for (i = 1;; i++)
  40. {
  41.  
  42. summ += (pow(-1, i-1) * pow(x, (2 * i - 1))) / fact(i);
  43. if (abs(sin(x)-summ)<= e)
  44. {
  45.  
  46. printf("\nn=%d", i);
  47. break;
  48. }
  49. }
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement