c语言,不是c++ 求圆周率的近似值,要求有效数字位数不少于30位

来源:百度知道 编辑:UC知道 时间:2024/05/30 22:55:11
求圆周率的近似值,要求有效数字位数不少于30位
程序可以的话肯定补分,诚信没问题
要c语言的,不要c++
有一个错误啊,
------------------Configuration: 1 - Win32 Debug--------------------
Compiling...
1.c
c:\documents and settings\孔虎\桌面\1.c(8) : warning C4047: '=' : 'unsigned long [106]' differs in levels of indirection from 'const int '
c:\documents and settings\孔虎\桌面\1.c(8) : error C2106: '=' : left operand must be l-value
c:\documents and settings\孔虎\桌面\1.c(14) : error C2296: '*' : illegal, left operand has type 'unsigned long [106]'
c:\documents and settings\孔虎\桌面\1.c(16) : warning C4047: '=' : 'unsigned long [106]' differs in levels of indirection from 'unsigned long '
c:\documents and settings\孔虎\桌面\1.c(16) : error C2106: '=' : left operand must be l-value
执行 cl.exe 时出错.

1.obj - 1 error(s), 0 warning(s)

从来跟你整了个,这个应该更好理解点,而且你想计算好多位就好多位,只需要修改第二句代码:
#include <stdio.h>
#define PI_DIGITS 30
#define PI_BUFFLEN (PI_DIGITS*14/4)
unsigned long b,c,d,e,f[PI_BUFFLEN+1],g, n;

int main()
{
for(b=0;b!=PI_BUFFLEN;b++) f=2000;
for (e=0,c=PI_BUFFLEN;c;c-=14)
{
d=0;
for(b=c;b;b--)
{
d += f*10000;
g = b*2-1;
f = d%g;
d /= g;
if (b>1) d *= b-1;
if (d>4000000000l)
printf("|%d\n",n);
}
printf("%.4d",e+d/10000);
n+=4;
e=d%10000;
}
return 0;
}