Advertisement
NIKOLAY_TETUS

check later

Nov 4th, 2021
1,088
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.57 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main()
  5. {
  6.     long double x;
  7.     printf("x> ");
  8.     scanf("%Lf", &x);
  9.  
  10.     if (fabsl(x) >= 0.5)
  11.     {
  12.         printf("x must be < 0.5, aborted.");
  13.         return 0;
  14.     }
  15.  
  16.     long double S = 0;
  17.     long double epsilon = 1e-4;
  18.  
  19.     long double diff;
  20.  
  21.     int it = 0;    //Now iteration
  22.  
  23.     do
  24.     {
  25.         diff = (1 + (pow(-1, it) * pow(2, it + 1))) * powl(x, it);
  26.         S += diff;
  27.         //printf("%Lf\n", diff);
  28.  
  29.         it++;
  30.     }while(fabsl(diff) > epsilon);
  31.  
  32.     printf("S: %Lf", S);
  33.  
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement