求圆周率,怎样输出前100位,或者N位.
就是那个1-1/3+1/5-1/7 ……,即使用双精度也只能输出没几位啊,那肯定要断开一位一位输出了,怎么做啊,头都大了,理了一点,懒得写下去了,高手给个答案void next(double a);
main()
{double a=1,b,c,d=-1,f,sum=1;
int e=1,h,i;
for(b=0;b<10;b++,e++)
{
f=sum*4;
h=f;
printf("sum1=%d\n",h);
{ a=a+2; c=a;
c=(d)*(1/c);
d=(-1)*d ;
sum+=c; }
i=4*sum ;
printf("sum2=%d\n",i);
if(h==i)
{ printf("%d=%d,\n",h,i) ;
a=a-4; sum=0; d=(-1)*d ; /*计算下一位*/
{ f=sum*10;
h=f;
printf("sumNEXT1=%d\n",h);
a=a+2; c=a;
c=(d)*(1/c);
d=(-1)*d ;
sum+=c; } }
if(e%10000==0)
{ e=1;
printf("yuan=%lf\n",4*sum); }
}
printf("yuan=%lf\n",4*sum);
getch();}
void next(double a)
{ double b,c,d=-1,f,sum=1;
int e=1,h,i,u;
if(h==i)
{ a=a-4; sum=0; d=(-1)*d ;
a=a+2; c=a; c=(d)*(1/c); d=(-1)*d ; sum+=c; i=sum1=sum*40; }
else
{a=a+2; c=a; c=(d)*(1/c); d=(-1)*d ; sum+=c; h=sum2=sum*40 }
if(h==i)
next(a);}
h=sum*10; }