fork download
  1. #include <stdio.h>
  2. main ()
  3. {int n, k, i;
  4. float a,b, c, x, p;
  5. printf ("Enter the desired number of decimal places:");
  6. scanf ("%d", &k);
  7. x=1;
  8. for (i=1; i<=k; i++)
  9. x=x*0.1;
  10. n=1;
  11. p=0;
  12. c=1;
  13. while (c>=x)
  14. {a=4/n;
  15. b=4/(n+2);
  16. c=a-b;
  17. p=p+c;
  18. n=n+4;}
  19. printf ("\nP=%f", p);
  20. }
Success #stdin #stdout 0s 9432KB
stdin
6
stdout
Enter the desired number of decimal places:
P=3.000000