诡异的程序

#include < iostream.h >
#include
< math.h >

void main()
... {
intsign=1,
doubles=0,x=1;
intk=1;
while(fabs(x)>1e-8)
...{
s
+=x;
k
+=2;
sign
=(-1)*sign;
x
=sign/double(k);
}

s
=s*4;

cout
<<s<<endl;
}

// 想用π/4=1-1/3+1/5-1/7......求π,但结果总是4

你可能感兴趣的:(程序)