用vb 求π Private Sub Form_Click()Dim i As Long,pi As Double,k As Integer,m As Doublei = 1k = 1pi = 0m = 1While (m > 0.00001)m = 1 / (2 * i - 1)pi = pi + k * mi = i + 1k = -kWendPrint "π "; 4 * piEnd SubPrivate Sub Form_Click()Dim pi,c,s As Single

来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/27 11:09:02
用vb求πPrivateSubForm_Click()DimiAsLong,piAsDouble,kAsInteger,mAsDoublei=1k=1pi=0m=1While(m>0.00001)m=

用vb 求π Private Sub Form_Click()Dim i As Long,pi As Double,k As Integer,m As Doublei = 1k = 1pi = 0m = 1While (m > 0.00001)m = 1 / (2 * i - 1)pi = pi + k * mi = i + 1k = -kWendPrint "π "; 4 * piEnd SubPrivate Sub Form_Click()Dim pi,c,s As Single
用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

用vb 求π Private Sub Form_Click()Dim i As Long,pi As Double,k As Integer,m As Doublei = 1k = 1pi = 0m = 1While (m > 0.00001)m = 1 / (2 * i - 1)pi = pi + k * mi = i + 1k = -kWendPrint "π "; 4 * piEnd SubPrivate Sub Form_Click()Dim pi,c,s As Single
这是级别展开式,你学到高等数学就会明白的
pi/4=1-1/3!+1/5!-1/7!+...