Guest User

KEK

a guest
Mar 6th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.96 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. //#include <time.h>
  4. //#include <limits.h>
  5.  
  6. void main() {
  7. //    INT_MAX
  8. //    clock_t begin = clock();
  9.  
  10.     int acc, n = 0, st;
  11.     long double S1=0, r, rr, an;
  12.  
  13.     scanf("input the accuracy: %d",&acc);
  14.     //acc = 8;
  15.     rr = pow(10,-(acc+1));
  16.     //r=pow(10,-acc);
  17.     st=1;
  18.  
  19.     do {
  20.         an = (long double)4*st/(2LL*n+1);
  21.         /*printf("%1.14f\n",an);*/
  22.         S1 += an;
  23.         n++;
  24.         st = -st;
  25. //        if (n % 100000 == 0)
  26. //            printf("%d\n", n);
  27. //        if (n >= 2000000000){
  28. //            printf("ALALALLALALAL");
  29. //        }
  30.     } while(fabs(an) >= rr);
  31.  
  32.     //printf("%f\n",S2);
  33.  
  34.     printf("%1.14f\n",S1);
  35.  
  36.     /*if(((S2/r)-(int)(S2/r))>=5*rr) {
  37.         S2o=S2-5*rr;
  38.       } else {
  39.         S2o=S2;
  40.       }*/
  41.  
  42.     /*printf("%f\n",S2o);*/
  43.  
  44.     printf("%d\n",n-1);
  45. //    clock_t end = clock();
  46. //    double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment