Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- int main()
- {
- long double x;
- printf("x> ");
- scanf("%Lf", &x);
- if (fabsl(x) >= 0.5)
- {
- printf("x must be < 0.5, aborted.");
- return 0;
- }
- long double S = 0;
- long double epsilon = 1e-4;
- long double diff;
- int it = 0; //Now iteration
- do
- {
- diff = (1 + (pow(-1, it) * pow(2, it + 1))) * powl(x, it);
- S += diff;
- //printf("%Lf\n", diff);
- it++;
- }while(fabsl(diff) > epsilon);
- printf("S: %Lf", S);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement