Advertisement
xotohop

cp12.3

Oct 31st, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.45 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int n, i;
  5. float p, c, sum = 0, e = 0.001, x;
  6.  
  7. double func(float x, int n)
  8. {
  9.     return (x + n) / powf(x, n);
  10. }
  11.  
  12. int main(void)
  13. {
  14.         scanf("%f", &x);
  15.         n = 1;
  16.         c = func(x, n);
  17.         sum += c;
  18.         n++;
  19.         do
  20.         {
  21.             p = c;
  22.             c = func(x, n);
  23.             sum += c;
  24.             n++;
  25.         } while (abs(c - p) > e);
  26.         printf("%f\n", sum);
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement