用vb 求π
问题描述:
用vb 求π
Private Sub Form_Click()
Dim i As Long,pi As Double,k As Integer,m As Double
i = 1
k = 1
pi = 0
m = 1
While (m > 0.00001)
m = 1 / (2 * i - 1)
pi = pi + k * m
i = i + 1
k = -k
Wend
Print "π "; 4 * pi
End Sub
Private Sub Form_Click()
Dim pi,c,s As Single
pi = 0
s = 1
For c = 1 To 10000 Step 2
pi = pi + s / c
s = -s
Next c
Print "π="; pi * 4
End Sub
答
这是级别展开式,你学到高等数学就会明白的
pi/4=1-1/3!+1/5!-1/7!+...我现在就想知道你知道什么是导数吗?你知道什么是泰勒展开式吗?导数肯定知道的后面那个不懂