#include <stdio.h> #include <math.h> int main(void) { int n = 1; double i = 1.0, pi, s = 0.0, x ; while(1) { x = i / n; if(fabs(x) <= 1e-6) break; s += x; i *= -1; n += 2; } pi = 4 * s; printf("pi的近似值是:%f\n", pi); return 0; }