![](https://cos-cdn.shuashuati.com/pipixue-web/2020-1231-2005-12/ti_inject-812ce.png)
所属年份: 2011.3;2012.9;2015.3 下列给定函数 fun 的功能是:根据以下公式求 π 值,并作为函数值返回。 例如,当给指定精度的变量 eps 输入 0.0005 时,应输出 Pi = 3.140578 。 π/2 = 1 + 1/3 + 1/3×2/5 + 1/3×2/5×3/7 + 1/3×2/5×3/7×4/9 + ...... 请改正的错误,使它能得出正确的结果。 注意:部分源程序在文件 MODI1.C 中 , 不得增行或删行,也不得更改的程序的结构! #include
#include
double fun(double eps) { double s,t; int n=1; s=0.0; /************found************/ t=0; while(t>eps) { s+=t; t=t *n/(2*n+1); n++; } /************found************/ return(s); } main() { double x; printf("\nPlease enter a precision: ");scanf("%lf",&x); printf("\neps=%lf, Pi=%lf\n\n",x,fun(x)); }