Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- //#include <time.h>
- //#include <limits.h>
- void main() {
- // INT_MAX
- // clock_t begin = clock();
- int acc, n = 0, st;
- long double S1=0, r, rr, an;
- scanf("input the accuracy: %d",&acc);
- //acc = 8;
- rr = pow(10,-(acc+1));
- //r=pow(10,-acc);
- st=1;
- do {
- an = (long double)4*st/(2LL*n+1);
- /*printf("%1.14f\n",an);*/
- S1 += an;
- n++;
- st = -st;
- // if (n % 100000 == 0)
- // printf("%d\n", n);
- // if (n >= 2000000000){
- // printf("ALALALLALALAL");
- // }
- } while(fabs(an) >= rr);
- //printf("%f\n",S2);
- printf("%1.14f\n",S1);
- /*if(((S2/r)-(int)(S2/r))>=5*rr) {
- S2o=S2-5*rr;
- } else {
- S2o=S2;
- }*/
- /*printf("%f\n",S2o);*/
- printf("%d\n",n-1);
- // clock_t end = clock();
- // double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
- }
Advertisement
Add Comment
Please, Sign In to add comment