我用vb设计了一个计算π的程序,怎么能让电脑多显示几位?
展开全部
Option Explicit
Private Sub Command1_Click()
getpi CLng(InputBox("生成多少位数(1-50000)的PI?", "提示", 5000))
End Sub
Sub getpi(Optional ByVal nums As Long = 10000)
nums = nums \ 5
Dim max As Long, laptime As Single, result() As String
Dim i, j As Long, d As Long, t, g, r, k As Long, f()
laptime = Timer
max = 10 * nums
ReDim f(1 To max)
ReDim result(nums)
result(0) = vbCrLf
For i = 1 To max
f(i) = 30000
Next
For j = max To 1 Step -10
t = 0
For i = j To 1 Step -1
If j = max Then
t = t + f(i) * 1000000
Else
t = t + f(i) * 100000
End If
r = 8 * i * (2 * i + 1)
f(i) = t - Int(t / r) * r
d = 2 * i - 1
t = Int(t / r) * d * d
Next
k = k + 1
result(k) = Format(Int(g + t / 100000) Mod 100000, "00000")
If k Mod 20 = 0 Then result(k) = result(k) & vbCrLf
If k Mod 200 = 0 Then result(k) = result(k) & "---[" & k * 5 & "]---" & vbCrLf
g = t Mod 100000
Next
Text1.Text = Join(result, " ")
Me.Caption = "计算完毕!总计用时" & Timer - laptime & "秒!"
End Sub
Private Sub Command1_Click()
getpi CLng(InputBox("生成多少位数(1-50000)的PI?", "提示", 5000))
End Sub
Sub getpi(Optional ByVal nums As Long = 10000)
nums = nums \ 5
Dim max As Long, laptime As Single, result() As String
Dim i, j As Long, d As Long, t, g, r, k As Long, f()
laptime = Timer
max = 10 * nums
ReDim f(1 To max)
ReDim result(nums)
result(0) = vbCrLf
For i = 1 To max
f(i) = 30000
Next
For j = max To 1 Step -10
t = 0
For i = j To 1 Step -1
If j = max Then
t = t + f(i) * 1000000
Else
t = t + f(i) * 100000
End If
r = 8 * i * (2 * i + 1)
f(i) = t - Int(t / r) * r
d = 2 * i - 1
t = Int(t / r) * d * d
Next
k = k + 1
result(k) = Format(Int(g + t / 100000) Mod 100000, "00000")
If k Mod 20 = 0 Then result(k) = result(k) & vbCrLf
If k Mod 200 = 0 Then result(k) = result(k) & "---[" & k * 5 & "]---" & vbCrLf
g = t Mod 100000
Next
Text1.Text = Join(result, " ")
Me.Caption = "计算完毕!总计用时" & Timer - laptime & "秒!"
End Sub
展开全部
用高精度算法。
算法代码比较复杂,但理论上算到任意位。网上有详细介绍。
算法代码比较复杂,但理论上算到任意位。网上有详细介绍。
追问
给个网址
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
汗...format(text1.text, "0.00000000000000000000000000000000000000000000000000000")
这样会怎样??我也没试过呢
这样会怎样??我也没试过呢
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询