编写函数fun,其功能是:根据以下公式求π的值(要求精度达到指定要求,即某项 小于eps时停止迭代)。 程序运行后,若输入精度为0.0005,则程序应输出为3.14...。 计算π的公式为:π/4=1-1/3+1/5-1/7+⋯+(-1)^(n-1)*1/(2n-1) 函数fun返回求出的π的值。 注意:请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入 你编写的若干语句。必须使用while语句。 # include
#include
//eps控制精度 double fun ( double eps) { double s=1.0,s1=1.0; int n=1; /**********Program**********/ /********** End **********/ } int main( ) { double x; printf("Input eps:") ; scanf("%lf",&x); printf("\neps = %lf, PI=%lf\n", x, fun(x)); return 0; }