#include <stdio.h>
#include <stdlib.h>
double fun(double x);
main()
{
double x;
printf(“最后一项绝对值的最小值:”);
scanf("%lf",&x);
printf(“π的近似值:%.6lf”,fun(x));
}
double fun(double x)
{
int i;
double a,sum=0,b;
for(i=0; ; i++)
{
b=2i+1;
a=1/b;
if(i%2==0)
sum+=a;
else sum-=a;
if(a<x)
break;
else continue;
}
return 4sum;
}