潜水衣与蝴蝶:求寻一道C语言题目的解法!!

来源:百度文库 编辑:高校问答 时间:2024/04/27 23:11:03
能帮我把这道C语言题目做出来吗,我在这里先谢谢了!
编写函数fun,它的功能是:根据以下公式求π(要求满足精度0.0005):π/2=1+1/3+(1*2)/(3*5)+(1*2*3)/(3*5*7)+……+(1*2*3*4*……*n)/(3*5*7*……*(2n+1))
好的话我会提高赏金的哦!

#include <stdio.h>

main()
{
double b,c,pai;
int i,j;

pai=1.0;b=1.0;i=1;j=3;

do{
c=b*(double)i/(double)j;
pai+=c;
b=c;
i++;j+=2;
}while (c>0.00001)

pai*=2;
printf("pai=%.5lf\n",pai);
}