fork download
  1.  
  2. #include <stdio.h>
  3. #include <math.h>
  4. int main() {
  5. double p=0.0,x;
  6. int n;
  7. x =pow(-1,n)/ (2 * n + 1);
  8. for(n=0;fabs(x)<=pow(10,-6);n++){
  9. p+=x;
  10. }
  11. p *= 4;
  12. printf("π 的近似值为:%.8f\n", p);
  13. return 0;
  14. }
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
π 的近似值为:0.00000000