代码:
#include
int main()
{
double sum=0;
int n=1;
int sign=1;
do
{
sum=sum+sign*1.0/n;
n=n+2;
sign=-sign;
}
while(1.0/n>=0.0001);
printf("π/4≈%.4fn",sum);
return 0;
}
运行结果:
π/4≈0.7853
Press any key to continue
代码:
#include
int main()
{
double sum=0;
int n=1;
int sign=1;
do
{
sum=sum+sign*1.0/n;
n=n+2;
sign=-sign;
}
while(1.0/n>=0.0001);
printf("π/4≈%.4fn",sum);
return 0;
}
运行结果:
π/4≈0.7853
Press any key to continue