void main()
{ double pi();
printf("%.5lf",2*pi());
getch();
}
double pi()
{ int i=+1 ;
double s=+1,k=+1;
while(s>=10e-6)
{
k = k* i /(2*i+1) ;
s += k;
i++;
}
return(s);
}
编译后结果居然是个负数..
编译核心是TurboC 2.0
void main()
{ double pi();
printf("%.5lf",2*pi());
getch();
}
double pi()
{ int i=+1 ;
double s=+1,k=+1;
while(s>=10e-6)
{
k = k* i /(2*i+1) ;
s += k;
i++;
}
return(s);
}
编译后结果居然是个负数..
编译核心是TurboC 2.0
void main() { double pi(); printf("%.5lf",2*pi()); getch(); } double pi() { int i=1 ; double s=1,k=1;
while(s>=10e6) //????是6 还是 -6??? { k = k* i /(2*i+1) ; s += k; i++; } return(s); }