📄 modi27.c
字号:
/*
下列给定程序中,函数fun的功能是:根据以下公式求π值,并作为函数值返回。例如,给指定精度的变量eps输入0.0005时,应当输出Pi=3.140578。
π/2=1+1/3+1/3x2/5+1/3x2/5x3/7+1/3x2/5x3/7x4/9+…
请改正程序中的错误,使它能得了正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
*/
#include <conio.h>
#include <math.h>
#include <stdio.h>
double fun (double eps)
{
double s, t; int n=1;
s=0.0;
/**********found************/
t=0;
/**********found************/
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));
}
/*
答案:
t=0;改为t=1.0;
while (t>eps)改为while (t>=eps)
return(s);改为 return(s*2);
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -