#include <math.h>
#include <stdio.h>
void main ()
{
int s;
float n,t,pi;
s=1,pi=0,n=t=1.0;
do
{
pi+=t;
n+=2;
s=-s;
t=s/n;
}while(fabs(t)>1e-5);
pi*=4;
printf("pi=%.9f\n",pi);
}
c语言 利用分式前n项和求圆周率
最新推荐文章于 2023-01-28 18:36:59 发布
#include <math.h>
#include <stdio.h>
void main ()
{
int s;
float n,t,pi;
s=1,pi=0,n=t=1.0;
do
{
pi+=t;
n+=2;
s=-s;
t=s/n;
}while(fabs(t)>1e-5);
pi*=4;
printf("pi=%.9f\n",pi);
}