#include<stdio.h>
#include<math.h>
main()
{
int s;
float n,t,pi;
t=1.0;
pi=0;
n=1.0;
s=1;
while(fabs(t)>=1e-6)
{
pi=pi+t;
n+=2.0;
s=-s;
t=s/n;
}
pi=pi*4;
printf("pi=%f\n",pi);
}
pi=3.141594
#include<stdio.h>
#include<math.h>
main()
{
int s;
float n,t,pi;
t=1.0;
pi=0;
n=1.0;
s=1;
while(fabs(t)>=1e-6)
{
pi=pi+t;
n+=2.0;
s=-s;
t=s/n;
}
pi=pi*4;
printf("pi=%f\n",pi);
}
pi=3.141594