编辑代码

#include <stdio.h>
int main () {
    float quarter_pi = 1;  //Initialize quarter of pi
    float i = 1;   //Denominator
    int j = 1;  //Cycles
    int l = 1;  //Positive and negative control
    int n = 1;  //Denominator number

    for(;j<1000000;j++){ //Loop 1,000,000 times
        n = n + 2;
        l = -l;
        i = l*n;
        quarter_pi = quarter_pi + (1/i);
    }

    printf("%f",4*quarter_pi); //Output
    return 0;
}