c语言程序设计根据下列公式前200项求出π的近似值 并将输出值存入pi中π/2=【1+1/(1*3)】*【1+1/(3*5)】*【1+1/(5*7)】*.
问题描述:
c语言程序设计根据下列公式前200项求出π的近似值 并将输出值存入pi中
π/2=【1+1/(1*3)】*【1+1/(3*5)】*【1+1/(5*7)】*.
答
//C语言实现如下:
double binary_PI(int n)
{
double result = 1.0;
int i = 0;
for (i=1; i<=n; i++)
result *= (1.0+1.0/((2*i-1)*(2*i+1)));
return result;
}
int main()
{
int n = 200;
printf("PI/2 = %lf\n", binary_PI(n));
return 0;
}
运行结果:
希望对您有所帮助!