求π的近似值,怎么做友友们

img

img


1.感觉结果不对,怎么改呢
2.有朋友分享下你的做法吗,感觉我的好麻烦🌹

img

供参考:

#include <stdio.h>
#include <math.h>
int main()
{
    int n = 10, i;
    double s = 0.5, t = 1;
    scanf("%d", &n);
    for (i = 1; i <= n; i++) 
    {
        t *= 1.0 * (2 * i - 1) / (2 * i);
        s += t * pow(0.5, (2 * i + 1)) / (2 * i + 1);
    }
    s *= 6.0;
    printf("%.9f", s);
    return 0;
}

为什么会有两重循环,你到底用的哪个求π的公式