我正在做一个程序,aproximate PI和我试图使用很久很久,但它不工作。 下面是代码如何长时间打印
#include<stdio.h>
#include<math.h>
typedef long long num;
main(){
num pi;
pi=0;
num e, n;
scanf("%d", &n);
for(e=0; 1;e++){
pi += ((pow((-1.0),e))/(2.0*e+1.0));
if(e%n==0)
printf("%15lld -> %1.16lld\n",e, 4*pi);
//printf("%lld\n",4*pi);
}
}
我猜你的问题更多的是'scanf'比'printf'更多。 – Nemo
'pow(( - 1.0),e)'会更好地表达为'e%2? 1:-1' –