Advertisement
Qellex

Untitled

Nov 11th, 2020
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.68 KB | None | 0 0
  1. #include "stdio.h"
  2. #include "locale.h"
  3. #include "math.h"
  4.  
  5.  
  6.  
  7. void main() {
  8.  
  9.     setlocale(LC_ALL, "rus");
  10.  
  11.     double x, eps, fx, n = 0, Sn = 1, s, a = -1;
  12.  
  13.     do {
  14.         printf_s("Введите x, -1 < x < 1: ");
  15.         scanf_s("%lf", &x);
  16.         printf_s("Введите eps: ");
  17.         scanf_s("%lf", &eps);
  18.     } while ((fabs(x) >= 1) || (eps < 0) || (eps > 1));
  19.  
  20.     fx = sqrt(1 + x);
  21.     s = Sn;
  22.  
  23.     while ((fabs(fx - s) > eps) && (n < 100000)) {
  24.         n++;
  25.         a *= -1;
  26.         Sn *= (a*((2*n-1)*(2*n))/(4*n*n*((1-2*n)/(-(1-2*(n-1))))))*x;
  27.         s += Sn;
  28.  
  29.     }
  30.  
  31.  
  32.     printf("fx = %12.10lf\ns = %12.10lf\nn = %12.10lf", fx, s, n);
  33.  
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement