//凯鲁嘎吉 - 博客园 http://www.cnblogs.com/kailugaji/
#include<stdio.h>
#include<math.h>
void main(){
int s=;
double n=1.0,t=1.0,pi=;
while(fabs(t)>1e-){ //fabs(double), abs(int)
pi=pi+t;
n=n+;
s=-s; //实现正负交替
t=s/n;
}
pi=pi*;
printf("π =%10.6lf\n",pi);
}
结果为: