0d=0g=2*cb=cDod=d" />

用EXCEL 将圆周率算到10000位

Public Const MAX As Long = 2500
'位数为max*4,不要设得太大,太大了,后面是无效数字
Sub pi()



Dim f(MAX * 14 + 1) As Long
a = 10000
b = 0
c = MAX * 14
d = 0
e = 0
g = 0
h = ""
For b = 0 To MAX * 14
f(b) = 2000
Next b

Do While c > 0
d = 0
g = 2 * c
b = c
Do
d = d + f(b) * a
g = g - 1
f(b) = d Mod g
d = d \ g
g = g - 1
b = b - 1
If b = 0 Then Exit Do
d = d * b
Loop
If e + d \ a < 1 Then
h = h + "0000 "
Else
If e + d \ a < 10 Then
h = h + "000" + Left(LTrim(Str(e + d \ a)), 1) + " "
Else
If e + d \ a < 100 Then
h = h + "00" + Left(LTrim(Str(e + d \ a)), 2) + " "
Else
If e + d \ a < 1000 Then
h = h + "0" + Left(LTrim(Str(e + d \ a)), 3) + " "
Else
h = h + Left(LTrim(Str(e + d \ a)), 4) + " "
End If
End If

End If
End If
e = d Mod a
c = c - 14
Loop
ActiveSheet.Cells(1, 1) = h
End Sub

相关文档
最新文档