下面函数pi的功能是:根据以下公式,返回满足精度(0.0005)要求的π的值,请填空.π/2=1+1/3+(1/3)*(2/5)+(1/3)*(2/5)*(3/7)+(1/3)*(2/5)*(3/7)*(4/9)+...\x05#include\x05#include\x05#include\x05double pi(double eps)\x05{\x05\x05double

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/11 04:36:00

下面函数pi的功能是:根据以下公式,返回满足精度(0.0005)要求的π的值,请填空.π/2=1+1/3+(1/3)*(2/5)+(1/3)*(2/5)*(3/7)+(1/3)*(2/5)*(3/7)*(4/9)+...\x05#include\x05#include\x05#include\x05double pi(double eps)\x05{\x05\x05double
下面函数pi的功能是:根据以下公式,返回满足精度(0.0005)要求的π的值,请填空.
π/2=1+1/3+(1/3)*(2/5)+(1/3)*(2/5)*(3/7)+(1/3)*(2/5)*(3/7)*(4/9)+...
\x05#include
\x05#include
\x05#include
\x05double pi(double eps)
\x05{
\x05\x05double s,t; int n;
\x05\x05for( 【1】; t>eps; n++)
\x05\x05{
\x05\x05\x05s+=t;
\x05\x05\x05t=n*t/(2*n+1);
\x05\x05}
\x05\x05return【2】 ;
\x05}
\x05void main()
\x05{
\x05\x05double x;
\x05\x05printf("\nPlease enter a precision:");
\x05\x05scanf("%lf",&x);
\x05\x05printf("\neps=%lf,π=%lf",x,pi(x));
\x05}

下面函数pi的功能是:根据以下公式,返回满足精度(0.0005)要求的π的值,请填空.π/2=1+1/3+(1/3)*(2/5)+(1/3)*(2/5)*(3/7)+(1/3)*(2/5)*(3/7)*(4/9)+...\x05#include\x05#include\x05#include\x05double pi(double eps)\x05{\x05\x05double
【1】s=0,t=1,n=1
【2】s*2
测试一下:
Please enter a precision:0.0001
eps=0.000100,π=3.141358