为什么给指定精度的变量eps输入0.0005时,应当输出Pi=3.140578
根据以下公式求PI值。例如,给指定精度的变量eps输入0.0005时,应当输出Pi=3.140578PI/2=1+1/3+(1/3)*(2/5)+(1/3)*(2/5)*(3/7)+(1/3)*(2/5)*(3/7)*(4/9)+...
程序代码:
#include<stdio.h>
main()
{
double r,eps,temp;
int m=1;
printf("\nPlease enter a precision: ");
scanf("%lf",&eps);
r=0.0;
/************found*********/
temp=0;
/************found*********/
while(temp<=eps)
{
r+=temp;
temp=(temp*m)/(2*m+1);
m++;
}
/************found*********/
printf("\neps=%lf,Pi=%lf\n\n",eps,r);
}
这个程序的答案我知道,但是不明白为什么这么改,请教各位大侠,谢谢!
[此贴子已经被作者于2016-4-17 11:11编辑过]









